wmguk Posted September 5, 2008 Share Posted September 5, 2008 Hey guys, I have a file upload script, but I want to specify maximum width and a maximum height of 200px (but not always square... may be 200px x 150px or 150px x 200px...) this is my script, is there anything I can do to it? <? //print_r($_POST); if($_POST["action"] == "Upload Image") { unset($imagename); if(!isset($_FILES) && isset($HTTP_POST_FILES)) $_FILES = $HTTP_POST_FILES; if(!isset($_FILES['image_file'])) $error["image_file"] = "An image was not found."; $imagename = basename($_FILES['image_file']['name']); //echo $imagename; if(empty($imagename)) $error["imagename"] = "The name of the image was not found."; if(empty($error)) { $imageid = $conamed . $imagename ; $newimage = "../images/logo/" . $imageid ; echo $newimage; include 'scripts/connection.php'; if (!$con) { die('Could not connect: ' . mysql_error() ); } mysql_select_db($db, $con); //Run the update query $sql = "UPDATE users SET logo = '$imageid' WHERE email = '$email'"; mysql_query( $sql , $con ) or die( "<strong>Query Error</strong>: " . mysql_error() . "<br><strong>Query</strong>: $sql<br><br>" ); $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(empty($result)) $error["result"] = "There was an error moving the uploaded file."; } } ?> <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>"> <p><input name="image_file" type="file" class="button" size="20"> </p> <p><input name="action" type="submit" class="button" value="Upload Image"> </p> </form> <? if(is_array($error)) { while(list($key, $val) = each($error)) { echo $val; echo "<br>\n"; } } ?> Thanks in advance Link to comment https://forums.phpfreaks.com/topic/122804-setting-size-200px-of-upload/ Share on other sites More sharing options...
wmguk Posted September 5, 2008 Author Share Posted September 5, 2008 I found list($width, $height, $type, $attr) = getimagesize($_FILES['image_file']['name']); if ($width > 200 || $height > 200) { echo "Maximum width and height exceeded. Please upload images below 200x200 px size"; exit(); } however I added it but it doesnt stop the file upload... Link to comment https://forums.phpfreaks.com/topic/122804-setting-size-200px-of-upload/#findComment-634148 Share on other sites More sharing options...
rarebit Posted September 5, 2008 Share Posted September 5, 2008 you can only limit by filesize. once up you can check and reject, but i'd just resize it... Link to comment https://forums.phpfreaks.com/topic/122804-setting-size-200px-of-upload/#findComment-634151 Share on other sites More sharing options...
wmguk Posted September 5, 2008 Author Share Posted September 5, 2008 you can only limit by filesize. once up you can check and reject, but i'd just resize it... Oh ok thats a pain, will the quality of an image thats say 1000 px wide, and then resized down to 200px be affected or will it stay ok? if it stays ok, how could I amend my script to resize after upload? Thanks Link to comment https://forums.phpfreaks.com/topic/122804-setting-size-200px-of-upload/#findComment-634158 Share on other sites More sharing options...
rarebit Posted September 5, 2008 Share Posted September 5, 2008 for resolution, I believe you'll have to size the image, but then say specify the size at output in html. However there probably is a way, see http://uk3.php.net/manual/en/book.image.php, or you could look at imagemagic Link to comment https://forums.phpfreaks.com/topic/122804-setting-size-200px-of-upload/#findComment-634161 Share on other sites More sharing options...
jordanwb Posted September 5, 2008 Share Posted September 5, 2008 I found this incredibly useful PHP class: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php Link to comment https://forums.phpfreaks.com/topic/122804-setting-size-200px-of-upload/#findComment-634183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.