sumfight Posted June 7, 2008 Share Posted June 7, 2008 I have been trying this since noon today, I wasted my whole day off of school and work Can someone just tell me what the best image resizer would be that would save the original file in one folder, the resized picture in another folder, so then I can put a random image generator tag on the page and call the new pictures form the new folder? Quote Link to comment https://forums.phpfreaks.com/topic/109069-tired-of-messing-around/ Share on other sites More sharing options...
hansford Posted June 7, 2008 Share Posted June 7, 2008 <form name="uploadform" enctype="multipart/form-data" method="post" action=<?php $_SERVER[php_SELF] ?>> Choose a file to upload:<input type="file" name="file01"/><br> <input type="submit" value="submit" name="action"/> </form> <?php if(isset($_FILES['file01'])) { $fil = $_FILES['file01']['name']; if($_POST["action"] == "submit"){ if(file_exists($_FILES['file01']['tmp_name'])) { $upload = $_FILES['file01']['tmp_name']; $filepath = $_SERVER['DOCUMENT_ROOT'] ."/images/" . $_FILES['file01']['name']; try { $err = move_uploaded_file($upload, $filepath); } catch(EXCEPTION $e) { echo $e; } } } } else { echo "upload failed"; } } $imgpath = "images/your_image_original.jpg"; $thumbpath = "thumbs/your_image_small.jpg"; $img = imagecreatefromjpeg($imgpath); $percent = 0.20; list($imgwidth,$imgheight) = getimagesize($imgpath); $newimgwidth = $imgwidth * $percent; $newimgheight = $imgheight * $percent; $newimage = imagecreatetruecolor($newimgwidth, $newimgheight); imagecopyresampled($newimage, $img,0,0,0,0,$newimgwidth, $newimgheight, $imgwidth, $imgheight); imagejpeg($newimage, $thumbpath,100); ?> mod edit - code tags added Quote Link to comment https://forums.phpfreaks.com/topic/109069-tired-of-messing-around/#findComment-559552 Share on other sites More sharing options...
sumfight Posted June 7, 2008 Author Share Posted June 7, 2008 <form name="uploadform" enctype="multipart/form-data" method="post" action=<?php $_SERVER[php_SELF] ?>> Choose a file to upload:<input type="file" name="file01"/><br> <input type="submit" value="submit" name="action"/> </form> <?php if(isset($_FILES['file01'])) { $fil = $_FILES['file01']['name']; if($_POST["action"] == "submit"){ if(file_exists($_FILES['file01']['tmp_name'])) { $upload = $_FILES['file01']['tmp_name']; $filepath = $_SERVER['DOCUMENT_ROOT'] ."/images/" . $_FILES['file01']['name']; try { $err = move_uploaded_file($upload, $filepath); } catch(EXCEPTION $e) { echo $e; } } } } else { echo "upload failed"; } } $imgpath = "images/your_image_original.jpg"; $thumbpath = "thumbs/your_image_small.jpg"; $img = imagecreatefromjpeg($imgpath); $percent = 0.20; list($imgwidth,$imgheight) = getimagesize($imgpath); $newimgwidth = $imgwidth * $percent; $newimgheight = $imgheight * $percent; $newimage = imagecreatetruecolor($newimgwidth, $newimgheight); imagecopyresampled($newimage, $img,0,0,0,0,$newimgwidth, $newimgheight, $imgwidth, $imgheight); imagejpeg($newimage, $thumbpath,100); ?> mod edit - code tags added Thanks for the help, I have this code which is great for a resize now, but I was wondering if you could tell me what to put into it to make the file names change, because if i have 5.jpg uploaded, and someone uploads another 5.jpg, the old one gets replaced <form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm"> <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /> <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button> </form> <?php if(isset($_POST['submit'])){ if (isset ($_FILES['new_image'])){ $imagename = $_FILES['new_image']['name']; $source = $_FILES['new_image']['tmp_name']; $target = "Lost/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "lost/" . $imagepath; //This is the new file you saving $file = "Lost/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 390; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; echo "<img src='Lost/".$imagepath."'><br>"; echo "You are wonderful for the upload, thanks "; } } ?> Also how to add it to a database too(but this one is not necessary) Quote Link to comment https://forums.phpfreaks.com/topic/109069-tired-of-messing-around/#findComment-559580 Share on other sites More sharing options...
digitalgod Posted June 7, 2008 Share Posted June 7, 2008 change $imagename = $_FILES['new_image']['name']; to whatever you want, you can even generate a random name using rand() as for the db part just add an INSERT query before echo "<img src='Lost/".$imagepath."'> might want to use sumfight's exception handling to see whether or not the image has been uploaded and resized before inserting in your db Quote Link to comment https://forums.phpfreaks.com/topic/109069-tired-of-messing-around/#findComment-559589 Share on other sites More sharing options...
sumfight Posted June 7, 2008 Author Share Posted June 7, 2008 change $imagename = $_FILES['new_image']['name']; to whatever you want, you can even generate a random name using rand() as for the db part just add an INSERT query before echo "<img src='Lost/".$imagepath."'> might want to use sumfight's exception handling to see whether or not the image has been uploaded and resized before inserting in your db I change it to this $imagename = $_FILES[rand()]; but it didn't work Quote Link to comment https://forums.phpfreaks.com/topic/109069-tired-of-messing-around/#findComment-559600 Share on other sites More sharing options...
sumfight Posted June 7, 2008 Author Share Posted June 7, 2008 As i didn't try the database part but I think I got it, you just name the fields you want in the php form and then in the database, then you connect to the database, right? Quote Link to comment https://forums.phpfreaks.com/topic/109069-tired-of-messing-around/#findComment-559602 Share on other sites More sharing options...
hansford Posted June 7, 2008 Share Posted June 7, 2008 yes, you can name the files whatever you want. Quote Link to comment https://forums.phpfreaks.com/topic/109069-tired-of-messing-around/#findComment-559693 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.