Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-07-2007, 08:58 AM   PM User | #1
mazazino
New to the CF scene

 
Join Date: Aug 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
mazazino is an unknown quantity at this point
ftp_put() successfull but with a problem

Hi, i used the following code to upload large files ranging 1-50 MB..the problem is i tried uploading a file of size 1.78 MB and it worked..then i tried uploading a file 2.9 MB and it didn't work..then i tried a uploading a file of size 2.18 MB and it also didnt work..by didnt work i mean that when checking the directory online, there is a file with the name of the uploaded file but its size is 0 bytes!!...i mean the uploading is fine, but the size is the problem..
the upload_max_filesize is set to 60MB just to make sure in wont cause a problem so im pretty sure that's not my problem..can anyone help?...


$ftp_server = "//ftp server";
$conn_id = ftp_connect($ftp_server);

// login with username and password
$ftp_user_name = "//username";
$ftp_user_pass = "//password";
$ftp_dir='/HOSTNAME.com/extras/softwares/'.$cat;

//$web_location is needed for the file_exists function, the directories used by FTP
//are not visible to it will will always return not found.
$web_dir='../../extras/softwares/'.$cat;
$local_file_name = $_FILES['directory']['name'];//"file.txt";
$source_file = $_FILES['directory']['tmp_name'];
$web_location=$web_dir.$local_file_name;

//build a fully qualified (FTP) path name where the file will reside
$destination_file=$ftp_dir.$local_file_name;

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}

//use ftp_site to change mode of the file
//this will allow it be visible by the world,
$ch=ftp_site($conn_id,"chmod 777 ".$destination_file);
// close the FTP stream
ftp_close($conn_id);
//verify file was written
if (file_exists($web_location))
{
echo "file was uploaded as $web_location";
}
else
{
echo "Could not create $web_location";
}
//end if
mazazino is offline   Reply With Quote
Old 08-07-2007, 04:28 PM   PM User | #2
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,744
Thanks: 2
Thanked 255 Times in 247 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
Your code blindly executes the ftp logic without ever checking if the upload was successful. I recommend adding some error checking, error reporting, and error recovery logic to your code by checking the $_FILES['directory']['error'] element and taking appropriate action depending on the value - http://www.php.net/manual/en/feature...oad.errors.php
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:41 AM.


Advertisement
Log in to turn off these ads.