$php_mysql$ Posted September 26, 2010 Share Posted September 26, 2010 could someone help in how to resize a uploaded image size, say if someone is uploading a 1mb photo to my server, i wish for it to become 100kb and also resize its width and height? here is my code //////////////////////////////////////uploader else if($action=="uploader") { echo "Upload your picture and copy the link <br/>after uploading to user it at gallery.<br/><br/>"; echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"index.php?action=uploaded&sid=$sid\">"; echo "Choose Picture: <br />"; echo "<input name=\"uploaded\" type=\"file\" /><br /><br />"; echo "<input type=\"submit\" value=\"Upload\" />"; echo "</form><br/>"; echo "<p align=\"center\">"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } //////////////////////////////////////uploader else if($action=="uploaded") { $blacklist = array(".php", ".php.jpg", ".php.jpeg", ".php.gif", ".php.png", ".phtml", ".php3", ".php4"); foreach ($blacklist as $item) { if(preg_match("/$item\$/i", $_FILES['uploaded']['name'])) { echo "<p align=\"center\">"; echo "Oops sorry we do not allow those files.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; exit; } } $target = "../images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if (file_exists("../images/" . $_FILES["uploaded"]["name"])) { echo "<p align=\"center\">"; echo $_FILES["file"]["name"] . "Oops file name already exists<br/> kindly rename your picture and upload again. <br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; }else{ //This is our size condition if ($uploaded_size > 25600){ echo "Your file is too large. We have a 25kb limit.<br/>"; $ok=0; } $types = array('image/jpeg', 'image/gif', 'image/png'); if (in_array($_FILES['uploaded']['type'], $types)) { // file is okay continue } else { $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0){ echo "<p align=\"center\">"; Echo "Sorry your file was not uploaded.<br/> It may be the wrong filetype. <br/>We only allow JPG, GIF, and PNG filetypes.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } //If everything is ok we try to upload it else{ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){ echo "<p align=\"center\">"; echo "The file ". basename( $_FILES['uploadedfile']['name']). " Picture uploaded successfully.<br/><br/><b>$target <br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } else{ echo "<p align=\"center\">"; echo "Sorry, there was a problem uploading your file.<br/>"; echo "<a href=\"index.php?action=main&sid=$sid\">Home</a>"; echo "</p>"; } } } } Quote Link to comment Share on other sites More sharing options...
litebearer Posted September 26, 2010 Share Posted September 26, 2010 perhaps this function could help... http://www.nstoia.com/toh/imageresize.php Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 26, 2010 Author Share Posted September 26, 2010 how could i implant it to my script above? could help me with it please? im new to all these. thanks Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 26, 2010 Author Share Posted September 26, 2010 any help around here anyone? Quote Link to comment Share on other sites More sharing options...
litebearer Posted September 26, 2010 Share Posted September 26, 2010 1. take the function I supplied you above and place it near the top of your script 2. at the point where you have successfully uploaded the image, implement the function adjusting the variables explained on the page I linked above. 3. In your post you talk about 1mb and 100k, yet your code only allows a 25k upload; which do you really want? Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted September 28, 2010 Author Share Posted September 28, 2010 well ill make it 1mb anything larger than that gets resized that is wht i want. guess ill have to remove the file size limit? Quote Link to comment Share on other sites More sharing options...
litebearer Posted September 28, 2010 Share Posted September 28, 2010 Yes, adjust the limit. BTW resolution, height and width are, primarily, what determine file-size. Decide what max height/width you want the images to have and the file-size will be adjusted accoringly. Quote Link to comment 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.