plugnz Posted May 17, 2010 Share Posted May 17, 2010 still trying to get my head around this multi image upload thing. Found this.... while(list($key,$value) = each($_FILES[images][name])) { if(!empty($value)){ // this will check if any blank field is entered $filename = $value; // filename stores the value $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line $add = "upimg/$filename"; // upload directory path is set //echo $_FILES[images][type][$key]; // uncomment this line if you want to display the file type // echo "<br>"; // Display a line break copy($_FILES[images][tmp_name][$key], $add); // upload the file to the server chmod("$add",0777); // set permission to the file. } } and tried to merge it with my current script thus: case 'Upload Image': [color=red] while(list($key,$value) = each($_FILES['image_filename']['name'])) { if(!empty($value)){[/color] $image_name = $_POST['image_name']; $image_group = $_POST['image_group']; $location_no = $_POST['location_no']; $category_name = $_POST['category_name']; $image_info = $_POST['image_info']; $image_date_taken = $_POST['image_date_taken']; $image_tempname = $value; $today = date("Y-m-d"); $ImageDir ="img/category/"; $ImageThumb = $ImageDir . "thumbnails/"; $ImageName = $ImageDir . $image_tempname; if (move_uploaded_file($_FILES['image_filename']['tmp_name'][color=red][$key][/color], $ImageName)) { list($width, $height, $type, $attr) = getimagesize($ImageName); if ($type > 3) { echo "Sorry, but the file you uploaded was not a GIF, JPG, or " . "PNG file.<br>"; echo "Please hit your browser's 'back' button and try again."; } else { $sql = "INSERT INTO cms_images_category " . "(image_name, image_group, location_no, category_name, image_info, image_date_taken, image_date) " . "VALUES ('" . $_POST['image_name'] . "','" . $_POST['image_group'] . "','" . $_POST['location_no'] . "','" . $_POST['category_name'] . "','" . $_POST['image_info'] . "','" . $_POST['image_date_taken'] . "','" . date("Y-m-d H:i:s", time()) . "')"; mysql_query($sql, $conn) or die('Could not insert content; ' . mysql_error()); $lastpicid = mysql_insert_id(); $newfilename = $ImageDir . $lastpicid . ".jpg"; if ($type == 2) { rename($ImageName, $newfilename); } else { if ($type == 1) { $image_old = imagecreatefromgif($ImageName); } elseif ($type == 3) { $image_old = imagecreatefrompng($ImageName); } $image_jpg = imagecreatetruecolor($width, $height); imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height); imagejpeg($image_jpg, $newfilename); imagedestroy($image_old); imagedestroy($image_jpg); } $newthumbname = $ImageThumb . $lastpicid . ".jpg"; $thumb_width = $width * 0.10; $thumb_height = $height * 0.10; $largeimage = imagecreatefromjpeg($newfilename); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); imagejpeg($thumb, $newthumbname); imagedestroy($largeimage); imagedestroy($thumb); } } [color=red] } }[/color] redirect('search.php?imageupload=yes&id=' . $lastpicid ); break; sorry that theres so much code here. but hopefully it will be clear. If anyone one could shed a bit of light on this that would be awesome. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/202037-mulitple-image-uploads-2/ Share on other sites More sharing options...
beta0x64 Posted May 17, 2010 Share Posted May 17, 2010 What exactly is the error that is occuring? It is difficult to tell what is wrong from just your code... Quote Link to comment https://forums.phpfreaks.com/topic/202037-mulitple-image-uploads-2/#findComment-1059626 Share on other sites More sharing options...
plugnz Posted May 17, 2010 Author Share Posted May 17, 2010 Hi sorry, error I'm getting is : Warning: Variable passed to each() is not an array or object in.... Could not redirect; Headers already sent (output). Quote Link to comment https://forums.phpfreaks.com/topic/202037-mulitple-image-uploads-2/#findComment-1059767 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.