Dorky Posted October 30, 2009 Share Posted October 30, 2009 $filepaths[] = $_FILES['new_image']; foreach ($filepaths as $filepath) { $imagename = strtolower($filepath['name']); $charref = substr($imagename, 0, strrpos($imagename, '.')); if(ctype_alnum($charref)) { this is for a form with multiple image uploads that need to be resized. im trying to loop them thrue the resize script but it over writes as it goes untill the only img when its done is the final image field. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted October 30, 2009 Share Posted October 30, 2009 Just a gues but you only have one image in $filepaths. So add an echo and see how many times your foreach is being executed. Quote Link to comment Share on other sites More sharing options...
Dorky Posted October 30, 2009 Author Share Posted October 30, 2009 i added $imgkey => and use it to rename the file and whats happening is it writes the final image as 0 so its as if my foreach loop isnt advancing thrue the array but it is because it because its running the first image but then overwriting it with the name of the first. Quote Link to comment Share on other sites More sharing options...
Dorky Posted October 30, 2009 Author Share Posted October 30, 2009 oh yeah, im running two images for testing Quote Link to comment Share on other sites More sharing options...
Dorky Posted October 30, 2009 Author Share Posted October 30, 2009 if (isset($_FILES['new_image'])) { if (!empty($_POST['address']) && !empty($_POST['city']) && !empty($_POST['state']) ) { //... $filepaths[] = $_FILES['new_image']; $listing = $_POST['address']; mkdir("/home/p14tnue3/public_html/howton/images/gallery/$listing" , 0755 ); mkdir("/home/p14tnue3/public_html/howton/images/gallery/thumbs/$listing" , 0755 ); foreach ($filepaths as $imgkey => $filepath) { $imagename = strtolower($filepath['name']); $charref = substr($imagename, 0, strrpos($imagename, '.')); if(ctype_alnum($charref)) { if (($pos = strrpos($imagename, ".")) === FALSE) { echo "<p class=\"p7\">Fail</p><br />"; exit; } else { $extension = substr($imagename, $pos + 1); $imagename = "$imgkey.$extension"; } if ( $extension == "jpg" || $extension == "gif" || $extension == "png" ) { $source = $filepath['tmp_name']; $target = "images/gallery/$listing/$imagename"; move_uploaded_file($source, $target); $file = "images/gallery/$listing/$imagename"; $save = "images/gallery/$listing/$imagename"; list($width, $height) = getimagesize($file) ; if ($width > "500" ) { $modwidth = 500; } else { $modwidth = $width ; } $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; if( $extension == "jpg" ) { $image = imagecreatefromjpeg ($file); } if( $extension == "gif" ) { $image = imagecreatefromgif ($file); } if( $extension == "png" ) { $image = imagecreatefrompng ($file); } imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; if( $extension == "jpg" ) { imagejpeg($tn, $save, 100) ; } if( $extension == "gif" ) { imagegif($tn, $save, 100) ; } if( $extension == "png" ) { imagepng($tn, $save, 9) ; } $save = "images/gallery/thumbs/$listing/$imagename"; list($width, $height) = getimagesize($file) ; if ($width > "100" ) { $modwidth = 100; } else { $modwidth = $width ; } $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; if( $extension == "jpg" ) { $image = imagecreatefromjpeg ($file); } if( $extension == "gif" ) { $image = imagecreatefromgif ($file); } if( $extension == "png" ) { $image = imagecreatefrompng ($file); } imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; if( $extension == "jpg" ) { imagejpeg($tn, $save, 100) ; } if( $extension == "gif" ) { imagegif($tn, $save, 100) ; } if( $extension == "png" ) { imagepng($tn, $save, 9) ; } $imginfo = "Images Uploaded Successfully"; $address = ""; $city = ""; $state = ""; } else { $imginfo = "Invalid or empty File <br>Valid file types .jpg .gif .png"; $address = $_POST['address']; $city = $_POST['city']; $state = $POST['state']; } } else { $imginfo = "Image name may have alphanumeric characters only and no spaces $charref"; $address = $_POST['address']; $city = $_POST['city']; $state = $POST['state']; } } //... } else { $imginfo = "Please complete all fields for listing"; $address = $_POST['address']; $city = $_POST['city']; $state = $POST['state']; } } Quote Link to comment Share on other sites More sharing options...
Dorky Posted October 30, 2009 Author Share Posted October 30, 2009 did a print_r its not over writing, its not retrieving all of the images from the form into the array. its only retrieving one in the array. $filepaths[] = $_FILES['new_image']; Quote Link to comment Share on other sites More sharing options...
WolfRage Posted October 30, 2009 Share Posted October 30, 2009 Right what you need to do is make a HTML array in your form so that all of the images are recieved not just the last image. Then you will want to capture either the entire $_FILES array or the HTML array that you create. http://php.net/manual/en/features.file-upload.php Quote Link to comment Share on other sites More sharing options...
Dorky Posted October 30, 2009 Author Share Posted October 30, 2009 yeah i figured that out but i have no idea how to get this into a workable array. it doesnt keep the right structure for some reason. this is the structure before and after the foreach loop indicated by "inside" and "outside" outside Array ( [name] => Array ( [0] => d.png [1] => sky.jpg ) [type] => Array ( [0] => image/png [1] => image/jpeg ) [tmp_name] => Array ( [0] => /tmp/phpX40sIK [1] => /tmp/php1TmAiS ) [error] => Array ( [0] => 0 [1] => 0 ) => Array ( [0] => 1028 [1] => 110116 ) ) inside Array ( [name] => [type] => [tmp_name] => [error] => 4 => 0 ) inside Array ( [name] => Array ( [0] => d.png [1] => sky.jpg ) [type] => Array ( [0] => image/png [1] => image/jpeg ) [tmp_name] => Array ( [0] => /tmp/phpX40sIK [1] => /tmp/php1TmAiS ) [error] => Array ( [0] => 0 [1] => 0 ) => Array ( [0] => 1028 [1] => 110116 ) ) Quote Link to comment Share on other sites More sharing options...
Dorky Posted October 30, 2009 Author Share Posted October 30, 2009 outside Array ( [name] => Array ( [0] => d.png [1] => sky.jpg ) [type] => Array ( [0] => image/png [1] => image/jpeg ) [tmp_name] => Array ( [0] => /tmp/phpeKr1qV [1] => /tmp/phpiII3hp ) [error] => Array ( [0] => 0 [1] => 0 ) => Array ( [0] => 1028 [1] => 110116 ) ) inside Array ( [0] => d.png [1] => sky.jpg ) inside Array ( [0] => image/png [1] => image/jpeg ) inside Array ( [0] => /tmp/phpeKr1qV [1] => /tmp/phpiII3hp ) inside Array ( [0] => 0 [1] => 0 ) inside Array ( [0] => 1028 [1] => 110116 ) 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.