0

我正在向我的站点添加 FTP 上传,并在实时测试时不断收到此错误。该脚本在我的本地主机上完全运行。

什么可能阻止它在我的虚拟主机的服务器上?

警告:ftp_login() 期望参数 1 是资源,布尔值在第 134 行的 /home/content/20/8630520/html/filedrop.php 中给出

    <div id="form">
    <?

    if(!isset($_POST["submit"])){?>

    <form action="filedrop.php" method="POST" enctype="multipart/form-data">
    <fieldset>
        <label><span class="error">*</span> Server:</label> 
        <input size="50" type="text" name="server" value=""/>

        <label><span class="error">*</span> Username:</label> 
        <input size="50" type="text" name="user"  value=""/>

        <label><span class="error">*</span> Password:</label> 
        <input size="50" type="password" name="password" value=""/>

        <label><span class="error">*</span> Select File:</label> 
        <input name="userfile" type="file" size="50" style="height:23px;"/>

        <input type="submit" name="submit" value="Upload" />
    </fieldset>
    </form>
    <?}
    else 
    {

    set_time_limit(300);//for uploading big files

    $paths=$_POST['pathserver'];

    $filep=$_FILES['userfile']['tmp_name'];

    $ftp_server=$_POST['server'];

    $ftp_user_name=$_POST['user'];

    $ftp_user_pass=$_POST['password'];

    $name=$_FILES['userfile']['name'];



    // set up a connection to ftp server
    $conn_id = ftp_connect($ftp_server);

    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

    // check connection and login result
    if ((!$conn_id) || (!$login_result)) {
    echo "1.) FTP connection has encountered an error!</br>";
    echo "2.) Attempted to connect to $ftp_server for user $ftp_user_name....</br>";
    echo "Go <a href=\"filedrop.php\">back</a> and try again.";
    exit;
    } else {
    echo "1.) Connected to $ftp_server, for user $ftp_user_name".".....</br>";
    }

    // upload the file to the path specified
    $upload = ftp_put($conn_id, $paths.'/'.$name, $filep, FTP_BINARY);

    // check the upload status
    if (!$upload) {
    echo "2.) FTP upload has encountered an error!</br>";
    echo "Go <a href=\"filedrop.php\">back</a> and try again.";
    } else {
    echo "2.) Uploaded file with name $name to $ftp_server ";
    echo "Go <a href=\"filedrop.php\">back</a> to upload more.";

    }

    // close the FTP connection
    ftp_close($conn_id);    

    }
    ?>
</div>

我需要修改这个吗?或者添加另一个文件?我不完全是 PHP 高级。

谢谢,

赛斯

4

1 回答 1

2

这意味着您的调用ftp_connect()失败并且您没有传递有效的资源 ID ftp_login()(实际上您传递false的是一个布尔值)。你需要弄清楚你ftp_connect()失败的原因。

于 2012-05-01T19:05:40.907 回答