Aan
Aan

Reputation: 12890

ftp_put returned TRUE but no file uploaded

Trying to upload a file to an FTP server using HTML form and PHP. My HTML form is:

<!DOCTYPE html>
<html>
<body>

<form action="uploader.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="files" id="files">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

uploader.php:

<?php
$conn_id = ftp_connect ( 'ftp.mydomain.com' );
$ftp_user_name="<username>";
$ftp_user_pass="<password>";

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

// check connection
if ((! $conn_id ) || (! $login_result )) {
    echo "FTP connection has failed!" ;
    exit;

} else {
    echo "Connected to for user $ftp_user_name" ;
}

if (empty($_FILES['files']['tmp_name'])) {
    echo "No file!!!!!!!!!";
    die();
}
// upload the file
$upload = ftp_put( $conn_id, "uploads/" , $_FILES['files']['tmp_name'] , FTP_BINARY );

// check upload status
if(!$upload){
    echo "FTP upload has failed!" ;
} else {
    echo "Successfully Uploaded." ;
}
?>

The output I got is Successfully Uploaded., but no file in actual can be found uploaded in the server.

uploads/ directory is located in the same uploader.php directory. Trying to change it to uploads/somename.zip shows that uploads/somename.zip is not a valid directoty.

Upvotes: 0

Views: 903

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202168

The second argument of ftp_put is a path to a remote file, not a path to a local directory.

So it should be like:

ftp_put($conn_id, "/remote/path/somename.zip", $_FILES['files']['tmp_name'], FTP_BINARY);

Also, you should use a passive mode. See PHP ftp_put fails.

Upvotes: 1

Related Questions