Gazz1982 Posted June 7, 2008 Share Posted June 7, 2008 Im using this code to upload an image from a form <?php $uploaddir = "uploads/"; $uploadfile = $uploaddir . $_FILES['upfile']['name']; if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile)) { print("File upload success"); } else { print("Failed"); } ?> I want add so that the file is also sent to another file This file needs to be a thumb nail so 100px wide is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/109129-upload-image/ Share on other sites More sharing options...
Gazz1982 Posted June 7, 2008 Author Share Posted June 7, 2008 I'm trying to upload an image from 1 file to to locations how can I combine these 2 scripts together <?php $uploaddir1 = "uploads/"; $uploadfile1 = $uploaddir1 . $_FILES['upfile']['name']; if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile1)) { print("File upload success"); } else { print("Failed"); } ?> <?php $uploaddir2 = "uploads/thumbs/"; $uploadfile2 = $uploaddir2 . $_FILES['upfile']['name']; if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile2)) { print("<br />Thumbnail upload success"); } else { print("<br />Thumbnail Failed"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/109129-upload-image/#findComment-559782 Share on other sites More sharing options...
AdRock Posted June 7, 2008 Share Posted June 7, 2008 I don't know if it wil help you but I have done what you are looking for I've attached my script so you can use the whole thing or grab what you want. When you upload a file, it uploads to a specific folder and it resizes it to a smaller image and a thumbnail image and it puts them in 2 seperate folders. So you end up with the original image, a medium resized image and a thumbnail [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/109129-upload-image/#findComment-559823 Share on other sites More sharing options...
hansford Posted June 7, 2008 Share Posted June 7, 2008 this if for a jpeg but you can do if/else statements for other image file s if(isset($_FILES['upfile'])) { $uploaddir1 = $_SERVER['DOCUMENT_ROOT'] ."/uploads/"; $uploadfile1 = $uploaddir1 . $_FILES['upfile']['name']; $upload = $_FILES['upfile']['tmp_name']; if(file_exists($_FILES['upfile']['tmp_name'])) { $err = move_uploaded_file($upload, $uploadfile1); if($err == FALSE){ echo "File upload success"; } else{ echo "Failed"; } } } $imgpath = $uploadfile1; $thumbpath = $uploaddir1 . "/thumbs/" . $_FILES['upfile']['name']; $img = imagecreatefromjpeg($imgpath); $percent = 0.20; list($imgwidth,$imgheight) = getimagesize($imgpath); if($imgwidth > $imgheight){ $newimgwidth = 100; $newimgheight = (100/$width) * $imgheight; } else { $newimgheight = 100; $newimgwidth = (100/$imgheight) * $imgwidth; } $newimgheight = $imgheight * $percent; $newimage = imagecreatetruecolor($newimgwidth, $newimgheight); imagecopyresampled($newimage, $img,0,0,0,0,$newimgwidth, $newimgheight, $imgwidth, $imgheight); imagejpeg($newimage, $thumbpath,100); $im = imagecreatefromjpeg($thumbpath); Quote Link to comment https://forums.phpfreaks.com/topic/109129-upload-image/#findComment-559848 Share on other sites More sharing options...
hansford Posted June 7, 2008 Share Posted June 7, 2008 Forget my previous post. I tried to write it off the top of my head without testing - it is buggy. This one I tested. the $flag variable sets the thumbnail width and based off that the height will be set so the thumb looks proportional. The script works for jpegs, but you can add if/else conditions to allow it to create any other image format. ------------------------------------------------------ <?php if(isset($_FILES['upfile'])) { $uploaddir1 = $_SERVER['DOCUMENT_ROOT'] ."/uploads/"; $uploadfile1 = $uploaddir1 . $_FILES['upfile']['name']; $upload = $_FILES['upfile']['tmp_name']; if(file_exists($_FILES['upfile']['tmp_name'])) { $err = move_uploaded_file($upload, $uploadfile1); if($err == FALSE){ echo "File upload failed"; exit(); } $imgpath = $uploadfile1; $thumbpath = $uploaddir1 . "/thumbs/" . $_FILES['upfile']['name']; $img = imagecreatefromjpeg($imgpath); list($imgwidth,$imgheight) = getimagesize($imgpath); echo $imgwidth . "<br>"; $flagwidth = 100; $percent = round(($flagwidth/$imgwidth) * 100) * .01; $newimgwidth = $imgwidth * $percent; $newimgheight = $imgheight * $percent; $newimgheight = $imgheight * $percent; $newimage = imagecreatetruecolor($newimgwidth, $newimgheight); imagecopyresampled($newimage, $img,0,0,0,0,$newimgwidth, $newimgheight, $imgwidth, $imgheight); imagejpeg($newimage, $thumbpath,100); $im = imagecreatefromjpeg($thumbpath); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/109129-upload-image/#findComment-559894 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.