[SOLVED] file upload error ($_FILE)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m_m
Forum Newbie
Posts: 9
Joined: Fri Jun 04, 2004 5:54 pm

[SOLVED] file upload error ($_FILE)

Post by m_m »

For some reason, when i try and upload a file, the $_FILE or $HTTP_POST_FILE array holds the info, but i can't extract it. It works fine when i am only uploading 1 file @ a time, but errors (and by error i mean, nothing is printed) with multiple. I'll expalin..

here is a snipet of code i am using to test the file upload

Code: Select all

$num_files = count($_FILES['IMG']['name']);

	for($x = 0; $x < $num_files; $x++)
	{ 
		echo "the files you picked are...<br>";
		echo $_FILES['IMG']['name'][$x];
	}
the HTML form code..

Code: Select all

&lt;form action="upload.php" method="POST" enctype="multipart/form-data"&gt;
&lt;input type="hidden" name="MAX_FILE_SIZE" value="200000" /&gt;&lt;br&gt;
File:&lt;input name="IMG" type="file" /&gt; &lt;br&gt;
File:&lt;input name="IMG" type="file" /&gt; &lt;br&gt;
File:&lt;input name="IMG" type="file" /&gt; &lt;br&gt;
File:&lt;input name="IMG" type="file" /&gt; &lt;br&gt;
...
&lt;input type="submit" value="Upload Files" /&gt;
&lt;form&gt;
when the form is submitted, the first echo line is printed ("the files.."), but thats it. Nothing happens with the rest. I am selecting files and I know they are in there when i do a print_r() on the array.

For some odd reason, it prints nothing wnen i use the [$x].

any ideas why this happens?
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

you are using same name, for all of your input values. this does not make them and array, instead one replaces others.
you must use different names for your input-tags.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

name="IMG&#1111;]"
m_m
Forum Newbie
Posts: 9
Joined: Fri Jun 04, 2004 5:54 pm

Post by m_m »

stupid mistakes.

thanks!
Post Reply