I’m hoping someone can help me with my problem. First, let me apologize for being wordy. This problem has me stumped and I want to explain it fully.
I’ve written a PHP upload routine using FTP commands to allow users to upload up to 5 files at a time through an html form, and it works fine for small files. I tried all the fixes suggested in other posts (php.ini, .htaccess, set_ini, etc.) and nothing worked. I finally contacted my server people and it turns out that there’s a server limit on communication time which effectively limits the file size to under about 2-2.5M.
Since 95% of the files uploaded will be below this, it’s not really a problem for me. However, there is that other 5%, so I thought I’d just insert some code that checked the files size and notify the user that the file was too large and the upload was skipped.
The code looks like this:
if(filesize($tmp_name)/1024 > 2048) {
echo "File: " . $tmp_name . " exceeds filesize limit. Upload failed.<p>";
}
else {
… rest of code …
The problem is that when it hits a large file, the code isn’t executed. If the user specifies 3 files, for example (small, large, small), the first and third are uploaded and the second times out. The notification to the user is that the first and third uploaded successfully, but nothing about the second. It’s like it never sees the code.
However, if I change the line to skip file sizes less than 2M (change the > to a <) it bypasses the first and third and times out on the second and tells the user that the first and third were skipped, but again, nothing about the second, so I don’t think it’s a coding problem.
Can someone give me some insight as to what’s going on here and, hopefully, how to fix it?
Thanks, here’s the complete code:
<?php
// set up basic connection
$ftp_server = "web1203.ixwebhosting.com";
$ftp_user_name = $_POST[user];
$ftp_user_pass = $_POST[passwd];
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
die("FTP connection has failed !");
}
foreach ($_FILES["graphicfile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$path= "".$HTTP_POST_FILES['graphicfile']['name'][$key];
$tmp_name = $_FILES["graphicfile"]["tmp_name"][$key];
$name = $_FILES["graphicfile"]["name"][$key];
if(filesize($tmp_name)/1024 > 2370) {
echo "File: " . $tmp_name . " exceeds filesize limit. Upload failed.<p>";
}
else {
if (ftp_put($conn_id, $name, $tmp_name, FTP_BINARY)) {
echo "File: " . $name . " uploaded successfully.<p>";
}
else {
echo "File: " . $tmp_name . " upload failed.<p>";
}
}
}
}
// close the connection
ftp_close($conn_id);
echo "<meta http-equiv='refresh' content='5;url=index.html'>";
?>