Reputation: 1489
I'm trying to upload an image file from my local PC to a remote server. The image comes from a simple html input (type=file) and file array contains these:
Array ( [name] => image42.jpg [type] => image/jpeg [tmp_name] => C:\wamp\tmp\phpBB52.tmp [error] => 0 [size] => 6051 )
As you can see, my local PC is using Windows. The code which tries to upload the image file is as follows:
$conn_id = ftp_connect($ftp_server, $ftp_port);
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
if(!ftp_chdir($conn_id, $folder_path))
{
$create_folder = ftp_mkdir($conn_id, $folder_path);
ftp_chmod($conn_id, 0777, $folder_path);
}
This perfectly connects to the server, even create a folder if it's not exist. Then when we get to the upload part,
ftp_pasv($conn_id, true);
// upload a file
$upload = ftp_put($conn_id, $new_dir, $file_dir, FTP_BINARY);
the variable $upload
gets false
.
$file_dir
contains C:\wamp\tmp\phpBB52.tmp
(i.e. file's tmp_name
).
$new_dir
contains the remote directory with image path: img.example.com/data/images/blabla.jpg
Also, the error returning is:
Warning: ftp_put() [<a href='function.ftp-put'>function.ftp-put</a>]: Could not create file. in C:\wamp\www\example\example.php on line 95
I have not found anything helpful neither on Google, nor StackOverflow. What could be the reason?
Upvotes: 4
Views: 17993
Reputation: 1969
My script was trying to upload a file periodically to a FTP location(overwriting the previously uploaded file with the same name) and was working fine.
It started showing this error now and I did delete the file from the FTP location and uploaded it again using the script and the error is gone.
The file must have been locked by any other application in the FTP location preventing its overwriting or maybe it was corrupt.
Upvotes: 0
Reputation: 2911
This worked for me. It could be the server's root directory is different from the FTP root directory.
Try logging into your FTP account with another program and check the root. For example, my FTP root is /public_html/
, but the server is /home/cms/public_html/
. So if my remote destination for my file was set to /home/cms/public_html/images/82.jpg
just change it to /public_html/images/82.jpg
.
Upvotes: 4