By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

upload to ftp through a php script

P: 89
Hi' all

I have a strange problem when uploading files from a form to my ftp site.

Here is my code:

$myFile = $_FILES['file']; // This will make an array out of the file information that was stored.
$file = $myFile['tmp_name']; //Converts the array into a new string containing the path name on the server where your file is.
$myFileName = $_POST['MyFile']; //Retrieve file path and file name
$myfile_replace = str_replace('\\', '/', $myFileName); //convert path for use with unix
$myfile = basename($myfile_replace); //extract file name from path
$destination_file = "/webshop/".$myfile; //where you want to throw the file on the webserver (relative to your login dir)
// connection settings
$ftp_server = ""; //address of ftp server (leave out ftp://)
$ftp_user_name = "xxxxxxxx"; // Username
$ftp_user_pass = "xxxxxxxx"; // Password
$conn_id = ftp_connect($ftp_server); // set up basic connection
// login with username and password, or give invalid user message
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<h1>You do not have access to this ftp server!</h1>");
$upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY); // upload the file
if (!$upload) { // check upload status
echo "<h2>FTP upload of $myFileName has failed!</h2> <br />";
// try to delete $file
if (ftp_delete($conn_id, $destination_file)) {
echo "$destination_file has been deleted!\n";
} else {
echo "Could not delete $destination_file!\n";
ftp_close($conn_id); // close the FTP stream

And this works okay, but when i upload files that has a size between about 1 MB - 2MB i get this error:

Warning: ftp_put(): Connection closed; transfer aborted. in D:\Webs\\httpdocs\konto\placeorder.php on line 15

FTP upload of Y:\\Medie-Design\\printlineweb\\www\\downloads\\alphastar_Pr has failed!

But the file goes into my folder on my ftp site.

When i then upload files biger than 2 MB i get this error:

FTP upload of Y:\\Medie-Design\\printlineweb\\www\\downloads\\ has failed!

And the files doesn't go into my ftp site.

My webprovider has an upload limit size of 2MB in their php ini file but i can't see this as a problem when i upload to my ftp site, which is located on a local windows 2003 server. OR is this a problem..????

Does anyone know why this happens, and maybe give me a solution to work around this...?

Thanks in advance!
Sep 18 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 938

I've recently had some issue with the FTP stuff in PHP. It seemed to me that the ini file set a maximum post size as well as a file upload size. As far as I can tell, and I'm no expert (anyone correct me?) you can't load files that exceed either size.

That's about all I know, fortunately for me my host has 8MB size so that's not too bad but still a pain.

If anyone has a better answer please post as I'd love to know how to get around this.

Oct 23 '08 #2

P: 110
post_max_size in php.ini needs to meet your requirement. maybe even upload_max_filesize, not too sure about that though.

you can read/change these values at runtime using ini_get() and ini_set()

also, ini_get() and ini_set() don't work with all settings. youll have to find out if they will work with post_max_size...i cant remember
Oct 23 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.