简体   繁体   中英

Unable To Upload File With FTP in PHP

Just now I got an error with my FTP file upload part. I am not able to upload a file via ftp using PHP. the code which I entered is as follows :

 <?php
$conn_id = ftp_connect(localhost);
$login_result = ftp_login($conn_id, 'newuser', 'wampp') or die("Could Not Connect To FTP Server");
$image = $_FILES['image']['tmp_name'];
$upload = ftp_put($conn_id, 'sri/image.jpg', $image, FTP_ASCII);
?>

The error that it shows is as follows :

Warning: ftp_put() [function.ftp-put]: Filename invalid in D:\xampp\htdocs\mycloud\edit.php on line 7

Please help me out of this stuff.

I think the process of uploading files via FTP has to be:

  1. Connect to FTP Server
  2. Login to the FTP Server (if applicable)
  3. Change to the right directory - (I believe you need to do this before attempting to upload the file in the sri folder). So you will need to go to the sri folder.
  4. Upload the file (so in your case it should be image.jpg only NOT sri/image.jp )
  5. and then close the connection to the FTP Server.

To change to current directory to the right directory, I think you need to do the following:

if(ftp_chdir($conn_id, "sri"))
{
    echo "Current directory is now: " . ftp_pwd($conn_id) ;
}
else 
{ 
    echo "Error could not change directory";
}

More info on changing directories

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