techker Posted March 15, 2010 Share Posted March 15, 2010 Hey guys i have this image uploader and resize script..it currently only uploads one image..i would like to mod it to upload 3 images.. here is the original code and below it is what i think to change <!doctype html public "-//w3c//dtd html 4.01 transitional//en"> <html> <head> <title></title> <?php //load the config file include("config.php"); //if the for has submittedd if (isset($_POST['upForm'])){ $file_type = $_FILES['imgfile']['type']; $file_name = $_FILES['imgfile']['name']; $file_size = $_FILES['imgfile']['size']; $file_tmp = $_FILES['imgfile']['tmp_name']; $Box = $_POST['Box']; $CAR_ID = $_GET['ID']; //check if you have selected a file. if(!is_uploaded_file($file_tmp)){ echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); //exit the script and don't do anything else. } //check file extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "Wrong file extension. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); } //get the file extension. $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; //create a random file name $rand_name = md5(time()); $rand_name= rand(0,999999999); //get the new width variable. $ThumbWidth = $img_thumb_width; //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list width and height and keep height ratio. list($width, $height) = getimagesize($file_tmp); $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } //function for resize image. if (function_exists(imagecreatetruecolor)){ $resized_img = imagecreatetruecolor($newwidth,$newheight); }else{ die("Error: Please make sure you have GD library ver 2+"); } imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //save image ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext"); ImageDestroy ($resized_img); ImageDestroy ($new_img); //print message echo "<br>Image Thumb: <a href=\"$path_thumbs/$rand_name.$file_ext\">$path_thumbs/$rand_name.$file_ext</a>"; } //upload the big image move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext"); echo "<br>Image Big: <a href=\"$path_big/$rand_name.$file_ext\">$path_big/$rand_name.$file_ext</a>"; echo "<br><br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; } ///////////////////////////insert part added mysql_connect("localhost", "techker_techker", "techker") or die(mysql_error()) ; mysql_select_db("techker_iapps") or die(mysql_error()) ; $DateHeure= date("Y-m-d H:i:s"); $query = "INSERT INTO AddOnImages ( CAR_ID, Box , Name, date ) VALUES ( NULL,'$CAR_ID','$Box','$rand_name.$file_ext','$DateHeure')" ; mysql_query($query) or die('Error, add album failed : ' . mysql_error()); //$id= mysql_insert_id(); //echo "<p>This file has the following Database ID: <b>$id</b>"; echo "You'll be redirected to Home Page after (4) Seconds"; echo "<meta http-equiv=Refresh content=4;url=ViewPost.php?ID=>"; // echo" </body> </html>"; ?> SO for shure in the form i need to add 2 more image file fields.called the imagefile2,imagefile3.since the first one is called imagefile. them im almost shure i need to add this $file_type3 = $_FILES['imgfile2']['type']; $file_name2 = $_FILES['imgfile2']['name']; $file_size2 = $_FILES['imgfile2']['size']; $file_tmp2 = $_FILES['imgfile2']['tmp_name']; $file_type 3= $_FILES['imgfile3']['type']; $file_name 3= $_FILES['imgfile3']['name']; $file_size 3= $_FILES['imgfile3']['size']; $file_tmp3 = $_FILES['imgfile3']['tmp_name']; To get the other images. Afther: $ext = strrchr($file_name,'.'); to $ext = strrchr($file_name,$file_name2,$file_name3,'.'); and $getExt = explode ('.', $file_name); to $getExt = explode ('.', $file_name,$file_name2,$file_name3); Afther im lost...is this good up to know? Quote Link to comment https://forums.phpfreaks.com/topic/195361-add-multiple-image-fileds/ Share on other sites More sharing options...
techker Posted March 16, 2010 Author Share Posted March 16, 2010 is this hard?or is it my post?lol Quote Link to comment https://forums.phpfreaks.com/topic/195361-add-multiple-image-fileds/#findComment-1026875 Share on other sites More sharing options...
karpagam Posted March 16, 2010 Share Posted March 16, 2010 Hi... See the attached folder.. I think that will be helpful for you........ Thanks [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/195361-add-multiple-image-fileds/#findComment-1026941 Share on other sites More sharing options...
techker Posted March 16, 2010 Author Share Posted March 16, 2010 nice it uploads but it dows not resize? Quote Link to comment https://forums.phpfreaks.com/topic/195361-add-multiple-image-fileds/#findComment-1027339 Share on other sites More sharing options...
karpagam Posted March 17, 2010 Share Posted March 17, 2010 Hi... Can you check here??? http://www.phpfreaks.com/forums/index.php?topic=232178.0 Quote Link to comment https://forums.phpfreaks.com/topic/195361-add-multiple-image-fileds/#findComment-1027428 Share on other sites More sharing options...
techker Posted March 17, 2010 Author Share Posted March 17, 2010 nice thx!! its all good but the thumbs dont work? <?php function resize($img, $thumb_width, $newfilename) { $max_width=$thumb_width; //Check if GD extension is loaded if (!extension_loaded('gd') && !extension_loaded('gd2')) { trigger_error("GD is not loaded", E_USER_WARNING); return false; } //Get Image size info list($width_orig, $height_orig, $image_type) = getimagesize($img); switch ($image_type) { case 1:$im = imagecreatefromgif($img);break; case 2: $im = imagecreatefromjpeg($img); break; case 3:$im = imagecreatefrompng($img); break; default: trigger_error('Unsupported filetype!', E_USER_WARNING); break; } /*** calculate the aspect ratio ***/ $aspect_ratio = (float) $height_orig / $width_orig; /*** calculate the thumbnail width based on the height ***/ $thumb_height = round($thumb_width * $aspect_ratio); while($thumb_height>$max_width) { $thumb_width-=10; $thumb_height = round($thumb_width * $aspect_ratio); } $newImg = imagecreatetruecolor($thumb_width, $thumb_height); /* Check if this image is PNG or GIF, then set if Transparent*/ if(($image_type == 1) OR ($image_type==3)) { imagealphablending($newImg, false); imagesavealpha($newImg,true); $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127); imagefilledrectangle($newImg, 0, 0, $thumb_width, $thumb_height, $transparent); } imagecopyresampled($newImg, $im, 0, 0, 0, 0, $thumb_width, $thumb_height, $width_orig, $height_orig); //Generate the file, and rename it to $newfilename switch ($image_type) { case 1: imagegif($newImg,$newfilename); break; case 2: imagejpeg($newImg,$newfilename); break; case 3: imagepng($newImg,$newfilename); break; default: trigger_error('Failed resize image!', E_USER_WARNING); break; } return $newfilename; } //This stuff is outside of the function. It operates with our images if(isset($_POST[submit])){ $imgNumb=1; //This the "pointer" to images $DestinationDir="upimg/"; //Place the destination dir here $ThumbDir="upimg/thumbs"; //Place the thumb dir here do{ $Unique=microtime(); // We want unique names, right? $destination=$DestinationDir.md5($Unique).".jpg"; $thumb=$ThumbDir.md5($Unique).".jpg"; $IMG=getimagesize($_FILES["img$imgNumb"][tmp_name]); echo resize($_FILES["img$imgNumb"][tmp_name], $IMG[0], $destination); $imgNumb++; } while($_FILES["img$imgNumb"][name]); }?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="" method="post" enctype="multipart/form-data" > <input type="file" name="img1"/> <input type="file" name="img2"/> <input type="file" name="img3"/> <input type="submit" name="submit" value="Submit"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/195361-add-multiple-image-fileds/#findComment-1027505 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.