Don't allow > 2mb images
17,073
Solution 1
2 MB is 2097152 bytes.
Change the 50000 to 2097152 and you're set.
Solution 2
The 5,000 is the number of byes, so basically you just need to convert 2MB to bytes. 1 MB is 1024 kilobytes, and 1024 bytes is 1 kilobyte. Doing the maths, we get:
2 megabytes = 2 097 152 bytes
Basically, you can calculate this in code form
$maxFileSize = $MB_limit * 1024 * 1024;
And check that the file size does not exceed $maxFileSize.
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
HI! How do i check if the users are trying to upload bigger than 2mb files? I would like to deny that and put an error message to the user who is trying to do that.
I know it is something like this, but what shall i change the 50000 to to become 2mb?
if ($_FILES['imagefile']['size'] > 50000 ) { die ("ERROR: Large File Size"); }
-
Admin almost 15 yearsYes i know that, but what to write in the max_upload_size variabel? To fit my suggestions? 2mb? Howto ;)
-
Lucas Jones almost 15 years2 MB = 2048 kilobytes. 2048KB = 2097152 bytes. (Apparently.)