Please see the snippet below. I am using it in a way to restrict files over 5 mb. Whenever the file is above 5 mb it says that “The file you attempted to upload is not allowed” when in fact it should say “The file you attempted to upload is too large.” It’s not that i placed them in the wrong part of the code, i am using:
if(filesize($_FILES['filename']['tmp_name']) > $max_filesize)
Entire code:
// Configuration - Your Options
$allowed_filetypes = array('.pdf','.jpg','.png','.gif');
$max_filesize = 5242880; // Maximum filesize in BYTES (currently 0.5MB).
$upload_path = "/store/user/$user";
$filename = $_FILES['filename']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['filename']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('');
Your filename extension code is not right, most likely.
Try with:
Otherwise, the file is basically not uploaded due to filesize constraints; you can check this by looking at
$_FILES['filename']['error']. The value should be 0.If it’s not 0, you can check here what it means: http://www.php.net/manual/en/features.file-upload.errors.php
In your case, the file is probably too big; check here what could be wrong: http://www.php.net/manual/en/features.file-upload.common-pitfalls.php