I'm working on a script to allow users to upload large (up to about 15M😎 binary files to a web server. They are then saved in a DB for later download. Everything works as expected when using small files (say under 1M😎. The script is supposed to generate an error message if the file hasn't uploaded properly, but with larger files, it gives every indication that it has uploaded correctly, but the file does not show up in the DB. And now I'm not sure how to troubleshoot this.
The server is running PHP 4.1.2 / MySQL 3.23.49 so a bit out of date.
Here's the relevant code snippet on the upload processing page:
if ($action=="add") {
// INSERT FILE AND DATA INTO DATABASE
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) {
$file_name = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$file_size = $_FILES['userfile']['size'];
$file_type = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); }
// INSERT INTO FILE TABLE
$query = "INSERT INTO fs_files (f_st, f_title, f_description, f_filename, f_size, f_type, f_d_id, f_idate, f_udate) VALUES ('1', '$f_title', '$f_description', '$file_name', '$file_size', '$f_type', '$d_id', '$now', '$now')";
if(mysql_query($query)) { }
else { die('There has been an error: The file information could not be saved to the database.'); }
// INSERT INTO STORED TABLE
$query = "INSERT INTO fs_stored (s_thefile, s_thetype) VALUES ('$content', '$file_type')";
if(mysql_query($query)) {}
else { die('There has been an error: The file could not be saved to the database.'); }
}
else { print "There has been an error: The file did not upload."; }
}
The script saves information about a file in one table and the file in another table. As I said, it works like a charm on small files, but nothing gets saved to the database with larger files. The file field on the form sets the maximum size to 16MB:
<input type="hidden" name="MAX_FILE_SIZE" value="16384000">
<input name="userfile" type="file" size="60" id="userfile">
The database table that stores the file is set to medium blob.
Any ideas where I'm going wrong?