473,383 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

upload to ftp through a php script

Hi' all

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

Here is my code:

[PHP]<?php
$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 = "ftp.printline.dk"; //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
?>[/PHP]

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\printline-webshop.eu\httpdocs\konto\placeorder.php on line 15

FTP upload of Y:\\Medie-Design\\printlineweb\\www\\downloads\\alphastar_Pr ocess_summary.zip 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\\artikel1.zip 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
2 3316
nathj
938 Expert 512MB
Hi,

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.

Nathj
Oct 23 '08 #2
developing
110 100+
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

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

Similar topics

4
by: Tihon | last post by:
Hello! I again need your help, just can't understand whats going on. Got this upload pictures form and it's having problem handling large files (~1.5 - 2 MB). Everything works fine if i just...
1
by: PeterB | last post by:
Hi! I'm using Pure ASP File Upload (http://www.asp101.com/articles/jacob/scriptupload.asp) to upload a file from a client to a server. I am testing both on a local IIS and a remote server. The...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
9
by: Steve Poe | last post by:
I work for an animal hospital trying to use PHP to store an animal's dental x-rays to a file server. I can browse for the xray on the local desktop computer then click "Upload Image". This...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need ...
5
by: camphor | last post by:
hi, I have found an upload script in hotscripts and have implemented it into the website, I followed the installation steps to 'give write permissions to php on the upload folder (which is...
24
by: owz2008 | last post by:
This has probably been covered before but could not find a similar thread. Basically I have created a form which can be viewed at www.icomworks.co.uk/canvaspayform.html I want to submit the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.