amoenum123
asked on
problem with php ftp_put command
I'm having a really difficult time trying to resolve this problem...here's the situation:
We have a personals website on one server and want to members to be able to upload and store videos of themselves. We want the videos to be stored on a different server.
I'm using the ftp functions in php to try and accomplish this. I seem to have no problems connecting to the server or logging in, but when it comes to actually transferring the files, the script is failing.
Here's the code:
$file = $userfile[$i];//temp file name
$remote_file = $vidname;
$tmpName = basename($userfile[$i]);
move_uploaded_file($file, $vid_working_dir."/".$tmpN ame) or die("Cannot move uploaded file to working directory");
// set up basic connection
$conn_id = ftp_connect($vid_ip_addres s,21) or die("Cannot initiate connection to host");
// login with username and password
$login_result = ftp_login($conn_id, $vid_username, $vid_password) or die("could not login");
// upload a file
$savepath = $vid_root_dir.$vid_file_pa th.$vidnam e;
$upload = ftp_put($conn_id, $savepath, $vid_working_dir."/".$tmpN ame, FTP_BINARY);
if (!$upload) {
echo "Cannot upload";
} else {
echo "Upload complete";
}
// close the connection
ftp_close($conn_id);
unlink($vid_working_dir."/ ".$tmpName ) or die("Cannot delete uploaded file from working directory -- manual deletion recommended");
My error logs are giving me the following:
ftp_put(): /var/www/vhosts/vid.xxxxxx .net/httpd ocs/videos /1_p61824. mpg: No such file or directory in /var/www/vhosts/xxxxxx.net /httpdocs/ php/upload videos.php on line 454, referer: http://xxxxxx.net/index.php?&action=uploadvideos
The video is being uploaded to the main server in the temp location without any problem.
What it looks like to me is that it's trying to find the file before it's actually uploaded....this is the first time I've tried to use the ftp commands so I have no experience with this command.
Your help is much appreciated...I'm on a deadline to get this site up and running!
Regards,
We have a personals website on one server and want to members to be able to upload and store videos of themselves. We want the videos to be stored on a different server.
I'm using the ftp functions in php to try and accomplish this. I seem to have no problems connecting to the server or logging in, but when it comes to actually transferring the files, the script is failing.
Here's the code:
$file = $userfile[$i];//temp file name
$remote_file = $vidname;
$tmpName = basename($userfile[$i]);
move_uploaded_file($file, $vid_working_dir."/".$tmpN
// set up basic connection
$conn_id = ftp_connect($vid_ip_addres
// login with username and password
$login_result = ftp_login($conn_id, $vid_username, $vid_password) or die("could not login");
// upload a file
$savepath = $vid_root_dir.$vid_file_pa
$upload = ftp_put($conn_id, $savepath, $vid_working_dir."/".$tmpN
if (!$upload) {
echo "Cannot upload";
} else {
echo "Upload complete";
}
// close the connection
ftp_close($conn_id);
unlink($vid_working_dir."/
My error logs are giving me the following:
ftp_put(): /var/www/vhosts/vid.xxxxxx
The video is being uploaded to the main server in the temp location without any problem.
What it looks like to me is that it's trying to find the file before it's actually uploaded....this is the first time I've tried to use the ftp commands so I have no experience with this command.
Your help is much appreciated...I'm on a deadline to get this site up and running!
Regards,
ASKER
sorry for not being clear on that part....
I'm not having any trouble with the file upload (using standard file upload in a form) and i've confirmed that it is storing it locally first.
The problem seems to lie when I attempt to transfer the file between servers. I have no problems connecting to the other server and can log in with the username and password fine.
I'm not having any trouble with the file upload (using standard file upload in a form) and i've confirmed that it is storing it locally first.
The problem seems to lie when I attempt to transfer the file between servers. I have no problems connecting to the other server and can log in with the username and password fine.
The issue is at what stage are you attempting the transfer out (ftp)? If you are attempting to do so from the script that handles the upload, double check that the ftp session does not begin until the upload is complete. Or use asynchronous transfer. I.e. when a file is uploaded mark its detail in a database. Then have a cron job or a process that checks the database for uploaded files and transfer them out.
ASKER
ok now i've tried running the following as a standalone process (knowing that the source file exists):
// set up basic connection
$conn_id = ftp_connect("vid.xxxxx.com ",21) or die("Cannot initiate connection to host");
// login with username and password
$login_result = ftp_login($conn_id, "username", "passwod") or die("could not login");
i
if(file_exists("/var/www/v hosts/xxxx x.com/http docs/workd ir/1_p6182 2.mpg"))
echo "file exists";
// upload a file
$upload = ftp_put($conn_id, "/var/www/vhosts/vid.xxxxx .com/httpd ocs/videos /thisvideo .mpg", "/var/www/vhosts/xxxxx.com /httpdocs/ workdir/1_ p61822.mpg ", FTP_BINARY);
if (!$upload) {
echo "Cannot upload";
} else {
echo "Upload complete";
}
i get the output "file exists" after the test for the source file and yet I still get "Cannot upload" as the result. My error logs are still telling me that the file doesn't exist. I'm pulling my hair out going crazy.
I'm able to connect to the server...
I'm able to log in.....
The source file exists....
The permissions on the destination directory are set properly...
// set up basic connection
$conn_id = ftp_connect("vid.xxxxx.com
// login with username and password
$login_result = ftp_login($conn_id, "username", "passwod") or die("could not login");
i
if(file_exists("/var/www/v
echo "file exists";
// upload a file
$upload = ftp_put($conn_id, "/var/www/vhosts/vid.xxxxx
if (!$upload) {
echo "Cannot upload";
} else {
echo "Upload complete";
}
i get the output "file exists" after the test for the source file and yet I still get "Cannot upload" as the result. My error logs are still telling me that the file doesn't exist. I'm pulling my hair out going crazy.
I'm able to connect to the server...
I'm able to log in.....
The source file exists....
The permissions on the destination directory are set properly...
ASKER
ok i seem to have made it a little bit further....
I've changed the destination path from
/var/www/vhosts/vid.xxxxx. com/httpdo cs/videos/ thisvideo. mpg
to
httpdocs/videos/thisvideo. mpg
and now it's actually started to create the file at the destination, but it's of zero size and won't go any further....
I've changed the destination path from
/var/www/vhosts/vid.xxxxx.
to
httpdocs/videos/thisvideo.
and now it's actually started to create the file at the destination, but it's of zero size and won't go any further....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
well i seem to be beating my head against the wall here....
thanks for your help arnold and your patience...i'm going to have to investigate this further using some other method because it's simply not working for me...I'm obviously missing something.
cheers
sean
thanks for your help arnold and your patience...i'm going to have to investigate this further using some other method because it's simply not working for me...I'm obviously missing something.
cheers
sean
Your best bet would be to get the file first and then have a cron or a scheduled process that would transfer the file. (Presumably you use a database.)