473,382 Members | 1,225 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

File Upload Problem

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
1 3815
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
3
by: Bijoy Naick | last post by:
I've written a simple file upload user control in VB .NET. It comprises of an InputFile HTML Server Control, an Upload button and a message label. User clicks on the Browse button of the...
6
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
5
by: William LaMartin | last post by:
I have a VB ASP.Net application where the user can upload a file using the FileUpload server control. I also want a thumbnail to be created for this file. Unfortunately I can see no means to...
4
by: riteshjain82 | last post by:
Hi, Please go through this: I am having a file (default.asp) on which i am taking many details from a user before mailing it to someone. I have also provided the user with a facility of...
6
by: Vic Spainhower | last post by:
Hello, I am trying to do a FTP file upload which works fine on my localhost but on my ISP server it fails. I can't seem to find where I can go to find the specific cause of the failure. In both...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
1
by: pbd22 | last post by:
hi. i have been posting this here and elsewhere a lot and can't seem to get resolution on this problem. i have been trying to upload files using a hidden iframe to a asp.net/vb.net form. the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.