Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/202037-mulitple-image-uploads-2/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.