Reply to Re: Database tmp name?

Re: Database tmp name? new!
by colin, 14 years ago
This is basic PHP, we are starting to get out of topic in this forum...

Your code should look like this then:

include('class.upload.php');

// create an array to hold your filnames
$images = array();

$files = array();
foreach ($_FILES['my_field'] as $k => $l) {
 foreach ($l as $i => $v) {
 if (!array_key_exists($i, $files))
   $files[$i] = array();
   $files[$i][$k] = $v;
 }
}      
foreach ($files as $file) {
  $handle = new Upload($file);
  if ($handle->uploaded) {
    $handle->Process("./");
    if ($handle->processed) {
      echo 'OK';
      // add the filename to the array
      $images[] = $handle->file_dst_pathname;
    } else {
      echo 'Error: ' . $handle->error;
    }
  } else {
    echo 'Error: ' . $handle->error;
  }
  unset($handle);
}

// you can insert the filenames in your database here, 
// from the array in which you stocked them
// but you will need to do some error checking, in case of the upload didn't work
$sql = "INSERT INTO photos2 (my_field1, my_field2, my_field3, my_field4) ";
$sql .= "VALUES ('".mysql_real_escape_string($images[0])."', '".mysql_real_escape_string($images[1])."', '".mysql_real_escape_string($images[2])."', '".mysql_real_escape_string($images[3])."')";
$x = mysql_query($sql) or die(mysql_error());
Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important