PHP - FTP文件上传错误

时间:2012-05-01 19:03:17

标签: php ftp

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

什么可以在我的网站主机的服务器上停止它?

  

警告: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高级版。

谢谢,

赛斯

1 个答案:

答案 0 :(得分:2)

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