robotman321 Posted July 28, 2008 Share Posted July 28, 2008 hi, so i got this here upload script, its fairly safe... now i am having a hard time implementing a dimension constriction, basically i want my members to be able to upload a 100x100 px image and below but not above.. i have looked around and tried many things but none seem to work, i was hoping someone could help me figure out what the heck i am doing wrong xD. Any and all help would be greatly appreciated!! CODE: if ($_POST['save']) { $imageinfo = getimagesize($_FILES['file']['tmp_name']); if($imageinfo[0] > 100 || $imageinfo[1] > 100 ) { echo 'um this file cannot complete'; } else { if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/bmp") && ($_FILES["file"]["size"] < 102401)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } //This applies the function to our file $ext = findexts ($_FILES["file"]["name"]); $avatarExtension = $ext; $avatarActivate = yes; $user1 = 'user'; //This line assigns a random number to a variable. You could also use a timestamp here if you prefer. $ran = $user1.$_SESSION['user_id']; //This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended. $ran2 = $ran."."; //This assigns the subdirectory you want to save into... make sure it exists! $target = "avatars/"; include 'connect/config.php'; include 'connect/newsOpenDb.php'; $query = 'UPDATE users SET avatarExtension=\'' . mysql_real_escape_string($avatarExtension) . '\', avatarActivate=\'' . mysql_real_escape_string($avatarActivate) . '\'WHERE Username=\'' . $name . '\''; mysql_query($query) or die('Error : ' . mysql_error()); include 'connect/closedb.php'; //This combines the directory, the random file name, and the extension $target = $target . $ran2.$ext; if (move_uploaded_file($_FILES["file"]["tmp_name"], $target)) { echo "<br /><br />Avatar Successfully Uploaded and updated.<br />"; } else { echo "Invalid file"; } } } } } thanks a load!! Quote Link to comment https://forums.phpfreaks.com/topic/116947-solved-image-upload-script-problemhelp-needed/ Share on other sites More sharing options...
ninedoors Posted July 28, 2008 Share Posted July 28, 2008 I found this tutorial good for me when I wanted to add a photo gallery to my website. You can change the size of the images to a max size. You can tweek it pretty easily as I did to get the images thumbnails and main pictures the way you want. http://www.sitepoint.com/article/php-gallery-system-minutes Quote Link to comment https://forums.phpfreaks.com/topic/116947-solved-image-upload-script-problemhelp-needed/#findComment-601552 Share on other sites More sharing options...
JonnoTheDev Posted July 28, 2008 Share Posted July 28, 2008 Rather than restricting image sizes why not just auto resize the image on upload. Image Magick can do this. Quote Link to comment https://forums.phpfreaks.com/topic/116947-solved-image-upload-script-problemhelp-needed/#findComment-601576 Share on other sites More sharing options...
robotman321 Posted July 28, 2008 Author Share Posted July 28, 2008 hmm well see, the function of this is for members of my site, where allowed, they can upload an avatar, and the system will spit back if it is too big.. i really dont want a manipulation script as much as where it looks at the image and stops the script and gives an error message if it is over, say 100 by 100 pixels.. EDIT: hmm maybe i will have to do that.....(resizer) Quote Link to comment https://forums.phpfreaks.com/topic/116947-solved-image-upload-script-problemhelp-needed/#findComment-601687 Share on other sites More sharing options...
robotman321 Posted July 28, 2008 Author Share Posted July 28, 2008 sorry for a double post.. but i found something simple xD and i thought i had done this but it works! $tmpName = $_FILES['file']['tmp_name']; list($width, $height, $type, $attr) = getimagesize($tmpName); if($width>100 || $height>100) { die("<br /><br />exceeded image dimension limits."); } Quote Link to comment https://forums.phpfreaks.com/topic/116947-solved-image-upload-script-problemhelp-needed/#findComment-601731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.