I am not sure about exact borders between these - the server is slow and testing got painfully long.
1) It uploads a single file up to 1.2MB fine
2) With a 3.81 MB ftp_put fails and I get my own error message.
3) With a 9MB single file if breakes Firefox (browser updated today) displaying a page entitled "Problem loading page" and a message starting with "The connection to the server was reset while the page was loading." and some useless pointers on how to fix the problem.
4) It uploads five tiny files fine.
5) I tried three files around 150 KB each and it uploaded fine.
6) It failed same as in 3) when I tried four files 150 KB - 200KB each.
I sure as heck don't really know where to even start fixing this... so anyone who could point me in the right direction will gain my eternal gratitude and a thankyou in the comments of my super FTP upload once it works
Here's some code for you guys to laugh at.
Code: Select all
function putFiles ($login,$password) {
$fileNames = array($_FILES["file1"]["name"], $_FILES["file2"]["name"], $_FILES["file3"]["name"], $_FILES["file4"]["name"], $_FILES["file5"]["name"]);
$tempNames = array($_FILES["file1"]["tmp_name"], $_FILES["file2"]["tmp_name"], $_FILES["file3"]["tmp_name"], $_FILES["file4"]["tmp_name"], $_FILES["file5"]["tmp_name"]);
$fileSizes = array();
$fileExtensions = array();
//Initialize sizes of the files
for ($i=0; $i<5; $i++) { //
$fileSizes[$i] = filesize($tempNames[$i]);
}
//Initialize array of file extensions
for ($i=0; $i<5; $i++) {
$ext = explode(".", $fileNames[$i]);
$fileExtensions[$i] = $ext[count($ext) - 1];
}
$MAX_FILE_SIZE = 100000 * 1024; // No files larger than 100 MB
$backstr = "<br><a href=\"index.php\">BACK</a>";
// An array with file extensions that are prohibited
$allExt = array("exe", "bat");
//Check if no files exceed the sizelimit
for ($i=0; $i<5; $i++) {
if ($fileSizes[$i] > $MAX_FILE_SIZE) {
die("File . $i .'s size exceeds $MAX_FILE_SIZE bytes.$backstr <br/>");
}
}
// Go thru all the files submitted
for ($i=0; $i<5; $i++) {
//Connect to FTP
$ftp_id = ftp_connect("ftp.totlpg.com");
$ftp_login = ftp_login($ftp_id,$login,$password);
if (!$ftp_login) {
ftp_quit($ftp_id);
die("Connection failed, check your login and password.$backstr <br/>");
}
//If file was submitted
if (!empty($fileNames[$i])) {
//Check is extension is not prohibited
if (!in_array(strtolower($fileExtensions[$i]), $allExt)) {
if (ftp_put($ftp_id,$fileNames[$i],$tempNames[$i],FTP_BINARY)) {
echo ("Uploading " . $fileNames[$i] . " was <FONT COLOR=\"red\">successful</font><br/>.");
ftp_quit($ftp_id);
}
//Check if upload succeded
else {
ftp_quit($ftp_id);
echo("<FONT COLOR=\"RED\">Upload failed for file " . ($i+1) . ". It is possible that a file with that name already exists on our server, please click BACK, change the name and try again.</font>" . $backstr ."<br/>");
}
}
else {
ftp_quit($ftp_id);
die ("ERROR - File " . ($i+1) . "'s extension is not allowed!" . $backstr . "<br/>");
}
}
}
}