Reply to Multiple File Uploads

Multiple File Uploads new!
by Roger, 12 years, 9 months ago
Hi,

Wonderful class!

I've been working on implementing it into my site and I've run into a problem. Multiple uploads. I've read the FAQ's and other posts on the forum, but I'm still lost. Here is what is going on...

I have 6 image fields on my form. Each one has been tested and they all work independently. Each has its own unique name. When processed, the class works fine and writes the file name to my database. Each image has it own row within my "users" table.

However, existing data within the db gets deleted once I upload an image to a secondary. ie.

1. Session one - the user logs in and uploads a profile picture.
2. Session two - the user logs in and uploads an image to a different row
3. The users original "profile" picture filename (in the db) gets deleted and the new one added to the appropriate row.

From what I understand, the loop is only needed if I'm uploading multiple files with the same name, correct?

Here is my form code...
<input type="file" name="pPic" />
<input type="file" name="Album1" />
<input type="file" name="Album2" />
<input type="file" name="Album3" />
<input type="file" name="Album4" />
<input type="file" name="Album5" />
<input type="file" name="Album6" />

and
if (POST_SUBMITTED!='' && $currentUser->getId() == $userid) {
$profilePic = new upload($_FILES['pPic']);
//checking to see if the users image folder exists. If not, create it.
$picroot = '../uImages/' . '$userid';
$result = file_exists($picroot);
if ($result === 0) {
  mkdir ("../uImages". "/" .$userid, 0777, TRUE); 
}
if ($profilePic->uploaded) {
  //$this_upload_ext = array();
  //$profilePic->this_upload_ext		= true;
  $profilePic->mime_check = true;
  $profilePic->allowed = array('image/*');
  $profilePic->file_new_name_body   = rand();
  $profilePic->image_resize         = true;
  $profilePic->image_x              = 100;
  $profilePic->image_ratio_y        = true;
  $pPic_upload = $profilePic->file_dst_name;
  $this_upload_ext = $profilePic->file_dst_name_ext;
  $profilePic->process("../uImages" . "/" .$userid);
}
if ($profilePic->processed) {
  //echo 'image resized';
  $pPic_upload = $profilePic->file_dst_name;
  $this_upload_ext = $profilePic->file_dst_name_ext;
  $profilePic->clean();
} else {
  $tplVars['error'] = T_($profilePic->error);
  //echo 'error : ' . $profilePic->error;
}
//This processes and uploads the photo album image #1
$Album1 = new upload($_FILES['Album1']);
if ($Album1->uploaded) {
  //$this_upload_ext = array();
  //$Album1->this_upload_ext		= true;
  $Album1->mime_check = true;
  $Album1->allowed = array('image/*');
  $Album1->file_new_name_body   = rand();
  $Album1->image_resize         = true;
  $Album1->image_x              = 100;
  $Album1->image_ratio_y        = true;
  $album1_upload = $Album1->file_dst_name;
  $this_upload_ext = $Album1->file_dst_name_ext;
  $Album1->process("../uImages" . "/" .$userid);
}
if ($Album1->processed) {
  //echo 'image resized';
  $album1_upload = $Album1->file_dst_name;
  $this_upload_ext = $Album1->file_dst_name_ext;
  $Album1->clean();
} else {
  $tplVars['error'] = T_($Album1->error);
  //echo 'error : ' . $Album1->error;
}

Thanks!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