By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

File Upload Problem

P: n/a
Hey all. I'm trying to upload multiple files. I'm using the chm file from
php.net to help me figure it out. I also checked online and say theres a
problem with the file. Anyway My html looks like this:

<form enctype="multipart/form-data" action="file-upload.php" method="post">
Send these file:<br>
<input name="userfile[0]" type="file"><br>
<input name="userfile[1]" type="file"><br>
<input name="userfile[2]" type="file"><br>
<input type="submit" value="Send File">
</form>
<form enctype="multipart/form-data" action="file-upload.php" method="post\">
<input type="hidden" name="MAX_FILE_SIZE" value="1500000">
Send this file:<br>
<input name="userfile" type="file"><br>
<input type="submit" value="Send File">
</form>

My file-upload.php is:

<?php
$uploaddir = "files/";
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir .
$_FILES['userfile']['name'])) {
print "File is valid, and was successfully uploaded. Here's some more
debugging info:\n";
print_r($_FILES);
}
else{
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}:
?>

This works for a single file and I've tried putting the <input type="hidden"
name="MAX_FILE_SIZE" value="1500000"> in the multiple file aswell and it
doesn't give me an error it just comes back with:

Possible file upload attack! Here's some debugging info:
Array
(
[userfile] => Array
(
[name] => Array
(
[0] => 1_1024x768.jpg
[1] => 2_1024x768.jpg
[2] => 3_1024x768.jpg
)
[type] => Array
(
[0] => image/pjpeg
[1] => image/pjpeg
[2] => image/pjpeg
)
[tmp_name] => Array
(
[0] => C:\WINDOWS\TEMP\php1A5.tmp
[1] => C:\WINDOWS\TEMP\php1A6.tmp
[2] => C:\WINDOWS\TEMP\php1A7.tmp
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
)
[size] => Array
(
[0] => 461796
[1] => 576646
[2] => 640622
)
)
)
Can someone help me please. I don't know what I'm doing wrong and I can't
figure it out.Thanks in advance.

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Mon, 16 Aug 2004 01:09:28 +0100, Muttly wrote:
Hey all. I'm trying to upload multiple files. I'm using the chm file from
php.net to help me figure it out. I also checked online and say theres a
problem with the file. Anyway My html looks like this:

<form enctype="multipart/form-data" action="file-upload.php" method="post">
Send these file:<br>
<input name="userfile[0]" type="file"><br>
<input name="userfile[1]" type="file"><br>
<input name="userfile[2]" type="file"><br>
<input type="submit" value="Send File">
</form>
<form enctype="multipart/form-data" action="file-upload.php" method="post\">
<input type="hidden" name="MAX_FILE_SIZE" value="1500000">
Send this file:<br>
<input name="userfile" type="file"><br>
<input type="submit" value="Send File">
</form>

My file-upload.php is:

<?php
$uploaddir = "files/";
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir .
$_FILES['userfile']['name'])) {
print "File is valid, and was successfully uploaded. Here's some more
debugging info:\n";
print_r($_FILES);
}
else{
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}:
?>

[ snip ]
You need to perform a loop.. you're trying to handle an array as a string
/ file. Try something like:
$errors = array();

for ($i = 0; $i < sizeof($_FILES['userfile']); $i++) {
$src = $_FILES['userfile']['tmp_name'][$i];
$dest = $uploaddir . $_FILES['userfile']['name'][$i];

if (!move_uploaded_file($src, $dest)) {
array_push($errors, $_FILES['userfile']['name'][$i];
}
}

if (sizeof($errors) > 0) {
foreach ($errors as $error) {
echo 'Failed to upload: ' . htmlentities($error) . "<br />\n";
}
}
HTH.

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.