Reply to Re: Mysql - Database

Re: Mysql - Database new!
by colin, 16 years, 9 months ago
This is a bit beyond the scope of this forum, but you can do like this for instance:
include('class.upload.php');
    
$files = array();
foreach ($_FILES['userfile'] 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_name_body_add = '_peque';
    $handle->file_auto_rename   = true;
    $handle->image_resize       = true;
    $handle->image_x            = 100;
    $handle->image_ratio_y      = true;
    $handle->Process("./test/");
    
    if ($handle->processed) {
      echo $handle->file_dst_name;
      // store the large image filename  
      $this_upload['large'] = $handle->file_dst_name;
    } else {
      echo 'error : ' . $handle->error;
    }
    
    $handle->file_auto_rename   = true;
    $handle->image_resize       = false;
    $handle->image_x            = 100;
    $handle->image_ratio_y      = true;
    $handle->Process("./test/");
    
    if ($handle->processed) {
      echo $handle->file_dst_name;
      // store the small image filename  
      $this_upload['small'] = $handle->file_dst_name;
      $handle->clean();
    } else {
      echo 'error : ' . $handle->error;
    }
    
    // add this set of pictures to the main array
    $uploaded[] = $this_upload;
  }
}

// now, you have all your picture names in $uploaded
// do your database insert like this for instance
$sql = "INSERT INTO photos (id, pic1, pic1_small, pic2, pic2_small....) ";
$sql .= "VALUES ('$id', '".$uploaded[1]['large']."', '".$uploaded[1]['small']."', '".$uploaded[2]['large']."', '".$uploaded[2]['small']."')");
$x = mysql_query($sql);
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