Page 1 of 1

NewbieQ - Multiple Photo Uploaded Via HTML Form

Posted: Thu Jun 27, 2002 12:18 pm
by toriboy
Hi, I am a PHP newbie.

I have a script that takes values (i.e name) & an image file from an HTML form then inserts the form values and the image in an HTML Document, then displays the results on the users browser.

Anyway, I have it working with 1 photo upload but cannot get it to work with more than one, can someone please tell me what I am doing wrong? perhaps give me the peice of code to correct the problem, below is my code.
I really need it to be able to upload multible files via the html form, I need at least 4 files.

The PHP Code
----------------

<?php
error_reporting (0);
//function handleupload() {
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
$filename = $_FILES['userfile']['tmp_name'];
//print "$filename was uploaded successfuly";

$realname = $_FILES['userfile']['name'];
//print "realname is $realname";

//print "copying file to uploads dir";

copy($_FILES['userfile']['tmp_name'], $realname);
} else {
echo "Possible file upload attack: filename ".$_FILES['userfile']['name'].".";
}

$Body = print <<<END

<html>
<head></head>
<body>
Test.....
</body>
</html>

END;

fclose($Body);
exit;
?>

--------End--------

The HTML Form Code
-------------------------

<form enctype="multipart/form-data" method="POST" action="ULtest_2.php?act=upload">
<input name="Name" size="18" maxlength="50" >
<input name="Email" size="18" maxlength="100" >
<input name="Onumber" size="18" maxlength="12" >
<input name="Company" size="18" maxlength="31">
<input type="FILE" name="userfile" size="35">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<input type="submit" value="Upload" name="B1">
</form>

--------End--------


Thanks
AJ

Posted: Thu Jun 27, 2002 2:19 pm
by volka
you may use

Code: Select all

<input type="FILE" name="userfile1" size="35"> 
<input type="FILE" name="userfile2" size="35"> 
<input type="FILE" name="userfile3" size="35"> 
<input type="FILE" name="userfile4" size="35">
or

Code: Select all

<input type="FILE" name="userfile&#1111;]" size="35"> 
<input type="FILE" name="userfile&#1111;]" size="35"> 
<input type="FILE" name="userfile&#1111;]" size="35"> 
<input type="FILE" name="userfile&#1111;]" size="35">
if the latter $_FILES['userfile']['tmp_name'] and similar are arrays, i.e.

Code: Select all

...
for ($i=0; $i!=count($_FILES&#1111;'userfile']&#1111;'tmp_name']); $i++)
&#123;
   $realname = processName($_FILES&#1111;'userfile']&#1111;'name']&#1111;$i]);
   copy($_FILES&#1111;'userfile']&#1111;'tmp_name']&#1111;$i], $realname);
   ...