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
https://forums.phpfreaks.com/topic/207393-uploading-photos-and-info/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.