Jump to content

Max File Size Suggestions?


Wayniac

Recommended Posts

Hey all, I am trying to figure out what the best way for me to try and set up a max file size (ex: 150kb) for my image upload script.

 

Here is an example of one of my previous attempts:

 

list($size, $width, $height, $type, $html_string, $mime) = getimagesize($_FILES['imagefile']['tmp_name']);

if ($size > 150000) {
echo "Error: Image SIZE must be 150kb or less.<br>";
echo "<a href=\"javascript:history.back()\">Return to previous page.</a>";
exit();
}

 

The code above is using a notation type of 1000. I also tried 1024 notation which was 153600 bytes (150kb). Neither of these worked properly. When I tried to upload a file that was 64kb, my error check popped up saying it was over 150kb. Is there something wrong with my code or the method I am approaching.

Link to comment
https://forums.phpfreaks.com/topic/190707-max-file-size-suggestions/
Share on other sites

getimagesize just gives you the dimensions of the image, not the filesize. the filesize is actually already present in the $_FILES[] array for the given file. have a look at the manual for handling file uploads:

 

PHP Manual: POST method uploads

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.