简体   繁体   中英

PHP - FTP file upload error

I am adding an FTP upload to my site and keep getting this error when testing it live. The script works fully on my localhost.

What could be stopping it on my web host's server?

Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home/content/20/8630520/html/filedrop.php on line 134

    <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>

Do I need to modify this? Or add another file? I'm not exactly PHP advanced.

Thank you,

Seth

It means your call to ftp_connect() failed and you don't have a valid resource ID being passed to ftp_login() (in fact you're passing false which is a boolean value). You need to figure out why your ftp_connect() is failing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM