cs1h Posted September 26, 2007 Share Posted September 26, 2007 Hi, Does anyone know of a way to limit the size of uploaded .jpg image files by putting a maximum pixel size on them. All help is much appriciated. Cheers Colin Link to comment https://forums.phpfreaks.com/topic/70806-limiting-upload-sizes/ Share on other sites More sharing options...
sljaxon Posted September 26, 2007 Share Posted September 26, 2007 There are two ways I can figure out how to do this. 1. Limit after upload to dimensions. 2. Limit before upload to file size. First 1: Let's assume that you've stored the upload in "uploads/image.jpg" and want to limit the size to 640x480. $imageSize = getimagesize("uploads/image.jpg"); if($imageSize[0] > 640 || $imageSize[1] > 480) { echo "invalid image: too big"; unlink("uploads/image.jpg"); } else { echo "Image OK."; } This is a suboptimal limitation method though, because the file has already been uploaded! To limit file size to 10KB, use code something like this in your upload script prior to storing the file. if($_FILES["imgFile"]["size"] < 10000) { echo "file too big"; } else { echo "file OK"; move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]); } That should work. Link to comment https://forums.phpfreaks.com/topic/70806-limiting-upload-sizes/#findComment-356025 Share on other sites More sharing options...
thyscorpion Posted September 26, 2007 Share Posted September 26, 2007 this might help: http://www.webcheatsheet.com/PHP/file_upload.php cheers Link to comment https://forums.phpfreaks.com/topic/70806-limiting-upload-sizes/#findComment-356026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.