...

View Full Version : Image Upload (multiple images at once)



mr mister x
09-03-2005, 08:24 PM
I have this script, which works perfectly:



<?php

require("fileupload-class.php");

$Referer = $_REQUEST['Referer'] ;
$path = "Images";
$upload_file_name = "userfile" ;
$acceptable_file_types = "image/jpeg|image/pjpeg";
$default_extension = "";
$mode = 2;

if (isset($_REQUEST['submitted'])) {

$my_uploader = new uploader($_POST['language']);
$my_uploader->max_filesize(99999999);

if ($my_uploader->upload($upload_file_name, $acceptable_file_types, $default_extension)) {
$my_uploader->save_file($path, $mode);
}

if ($my_uploader->error) {
echo $my_uploader->error . "<br><br>\n";

} else {
print("Your file: <br>" . $my_uploader->file['name'] . " <br>was successfully uploaded!");

if(stristr($my_uploader->file['type'], "image")) {

} else {
$fp = fopen($path . $my_uploader->file['name'], "r");
while(!feof($fp)) {
$line = fgets($fp, 255);
echo $line;
}
if ($fp) { fclose($fp); }
}
}
}

?>


However i would like to be able to upload multiple images at the same time, by having multiple browse boxes on the form and then simply hitting the upload button should upload all the files selected.

anshul
09-03-2005, 10:54 PM
It's possible using files array in a basic html form. Then loop a PHP script.

mr mister x
09-03-2005, 10:59 PM
could you please elaborate on that please. (sample code)

missing-score
09-04-2005, 01:15 AM
What I would do (based on your current script and ease of changing it), is name your form fields like this:



<input type="file" name="files[]" />
<input type="file" name="files[]" />
<input type="file" name="files[]" />


And then you can loop through and run the action on the files, regardless how many submitted...



<?php

for($i=0;$i<count($_FILES['files']['name']);$i++)
{
$filename = $_FILES['files']['name'][$i];
// Do rest of file upload as required...
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum