Hello,
I'm working on some upload file functionality and have run into the following problem.
The application is setting the MAX_FILE_SIZE constant, and anytime an image is upload greater than this size the app blows with an ugly error.
I need to somehow catch this error and display a nicer message to the user.
I've tried using filesize() to do a compare on the max size, but the function blows with the same error.
Here's the code:
if ($action == "upload") {
// check the filesize
if(filesize($binFile) > $max_agent_upload) {
echo "The file is too big!";
exit;
} else {
if (isset($binFile) && $binFile != "none") {
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO agent_tbl_Files ";
$sql .= "(description, bin_data, filename, filesize, filetype, owner, agentnum) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type', '$current_user', '$current_user')";
if (!mysql_query ($sql, $link) ) {
die (mysql_error());
}
echo "Your image has been added ($binFile_name).";
}
}
}
It works fine when the image is less than the max size.
Any help would be greatly appreciated.
Thanks,
John