Multiple image upload filenames

See all posts See thread Reply

Re: Multiple image upload filenames new!
by Matt, 14 years, 8 months ago
Apologies, I missed off one part of the code. Thanks

//initialize new images to be uploaded
$files = array();
foreach ($_FILES['image'] as $k => $l) {
  foreach ($l as $i => $v) {
    if (!array_key_exists($i, $files))
      $files[$i] = array();
    $files[$i][$k] = $v;
  }
}

// create an array here to hold file names
$uploaded = array();

foreach ($files as $file) {
  $handle = new Upload($file);
  if ($handle->uploaded) {
    // create a little array for this set of pictures
    $this_upload = array();
      
    $handle->file_safe_name 	= true;
    $handle->file_auto_rename   = true;
	$handle->file_max_size 		= '512000';
	$handle->allowed			= array('image/jpeg', 'image/jpg');
    $handle->Process($dir_dest);
    
    if ($handle->processed) {
      echo $handle->file_dst_name;
      // store the image filename  
      $this_upload['image'] = $handle->file_dst_name;
    } else {
      echo 'error : ' . $handle->error;
    }
    
    // add this set of pictures to the main array
    $uploaded[] = $this_upload;
  }
}
Reply
Re: Multiple image upload filenames new!
by colin, 14 years, 8 months ago
This is not really an upload problem. Check the keys in the $files array, in order to know which image has to be updated.Reply