justlukeyou Posted March 30, 2013 Share Posted March 30, 2013 Hi, I have code which uploads an image however I am stuck on how to restrict the height of an uploaded image. I can displays images once they are uploaded but if someone uploads a very tall images then it ruins the whole design of the site. I have gone through these sites but I am now more confused. Can anyone advise the best route to take to restrict an image upload? http://stackoverflow.com/questions/4612289/resize-image-on-upload-php http://www.9lessons.info/2009/03/upload-and-resize-image-with-php.html http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/ if ($_FILES['uploadLogo']['tmp_name'] != "") { // Run error handling on the file // Set Max file size limit to somewhere around 2mb $maxfilesize = 3145728; //size in bytes // Check file size, if too large exit and tell them why if($_FILES['uploadLogo']['size'] > $maxfilesize ) { echo "<br /><br />Your logo image was too large. Must be 3Mb or less, please<br /><br /> <a href=\"gallery_upload.php\">click here</a> to try again"; unlink($_FILES['uploadLogo']['tmp_name']); exit(); // Check file extension to see if it is .jpg, if not exit and tell them why } else if (!preg_match("/\.(gif|png|jpg|jpeg)$/i", $_FILES['uploadLogo']['name'] ) ) { echo "<br /><br />Your image was not .jpg, please<br /> <a href=\"gallery_upload.php\">click here</a> to try again"; unlink($_FILES['uploadLogo']['tmp_name']); exit(); // If no errors on the file process it and upload to server } else { // Set the direntory for where to upload it, use the member id to hit their folder // Upload the file /*if(isset($_GET['id'])){ if (!is_dir('memberFiles/'.$id.'/images/')) { //if memberFiles folder does not exist mkdir('memberFiles/'.$id.'/images/'); //make the folder }*/ if (!is_dir('images/')) { //if memberFiles folder does not exist mkdir('images/'); //make the folder } $target_path = 'images/'; //set targetpath } //adjust target path to create new file name which include $id and current date and original filename $ref = "-". gmdate('jmyhis') ."-". basename( $_FILES['uploadLogo']['name']); $target_path .= $ref; $filename = basename($_FILES['uploadLogo']['name']); $date = gmdate('j-m-y h:i:s'); $filename; if(move_uploaded_file($_FILES['uploadLogo']['tmp_name'], $target_path)) { mysql_query("UPDATE users SET logo='$ref' WHERE id='$myID'"); echo "Your image ".$filename." has been uploaded"; } else { echo "There was an error uploading the logo file, please try again!"; } } Link to comment https://forums.phpfreaks.com/topic/276332-restrict-height-of-uploaded-image/ Share on other sites More sharing options...
timothyarden Posted March 30, 2013 Share Posted March 30, 2013 $image_info = getimagesize($_FILES["file_field_name"]["tmp_name"]);$image_width = $image_info[0];$image_height = $image_info[1]; http://stackoverflow.com/questions/8486414/check-image-dimensions-height-and-width-before-uploading-image-using-php then do an if checking the image height and width is below the maximum amount you would like Link to comment https://forums.phpfreaks.com/topic/276332-restrict-height-of-uploaded-image/#findComment-1422019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.