NewbieQ - Multiple Photo Uploaded Via HTML Form
Posted: Thu Jun 27, 2002 12:18 pm
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
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