Jump to content

uploading photo's and info


dan_t

Recommended Posts

Hi all,

How would I go about entering multiple photo's and then the first and last name and email address from a from.

if (!isset($_GET['subpage'])) {   // Image Upload Form Below   ?> 
  <form method="post" action="addphoto.php?subpage=upload" enctype="multipart/form-data"> 
   Photo1:<br /> 
  <input type="file" name="imagefile" class="form"> 
  <br /><br /> 
  Photo2:<br />
  <input type="file" name="imagefile" class="form"> 
   <br /><br />
  <input name="submit" type="submit" value="Submit" class="form">  <input type="reset" value="Clear" class="form"> 
  </form> 
<?php
} else  if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {   // Uploading/Resizing Script 
  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use 
  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg")

On this one image works, I added another input, but don't know how to add a second file to the

$_FILES['imagefile']['name'];   

part.

Link to comment
Share on other sites

Hi,

 

Just change the name of the file inputs into name="imagefile[]". Afterwards, when processing it in PHP, treat $_FILES['imagefile']['name'] as an array.

 

To clarify:

foreach($_FILES['imagefile'] as $file){
   $file_name = basename($file['name']); // and here would be your file name - basename is good practice
   $errors = $file['error']; // any errors on upload
   $image_temp = $file['tmp_name']; //this is the temp name/address of the actual uploaded file
   $image_type = $file['type']; // this is the file type (jpeg, png, pdf, ect...)
   
   move_uploaded_file($image_temp, $destination.$file_name); 
   @unlink($image_temp); // don't forget to delete the temp image
}

 

That should pretty much do it for you

Link to comment
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.