I have a starting base and I had the idea of using an array name similar to the checkboxes where you would use checkbox[] and let it repeat through a for loop, in this case file[]. But when I go to access it via $_FILES'] it errors. I think there is something wrong with my logic as it is looking wrong but I feel it should work

Any Ideas?

Thanks, Regards X

9 Years
Discussion Span
Last Post by dhwaniparikh

Thanks Nav33n to the PHP rescue ;)

Theres way too much code to copy n paste so I will try break it up best I can, code:

switch($_POST['submit']) {
case 'UPLOAD':
now a whole bunch of code access variables and databases then

$file = $_FILES['file']['name'];

again a whole bunch of code

<input type="file" id="file" name="file">
<input type="submit" id="submit" name="submit" value="UPLOAD">

Thats the nuts of my code im trying to get working. (This works)
But im trying to make the type="file" an array id/name so its like id="file[]" name="file[]".
Then call it again at $_FILES']; using a for loop using 'index'.

Anyways no luck ill try again in the morning, any ideas?

Thanks Again, Regards X

	if(isset($_POST['submit'])) {
		for($i=0;$i<count($_FILES['fileupload']);$i++) {
			print $_FILES['fileupload']['name'][$i]."<br />";
<form name="upload" method="post" action="upload.php" enctype="multipart/form-data">
<input type="file" name="fileupload[]">
<input type="file" name="fileupload[]">
<input type="file" name="fileupload[]">
<input type="file" name="fileupload[]">
<input type="submit" name="submit">

This works for me! :)

Votes + Comments
Gave me a working example

Man I dont know what to say...

Your a PHP Guru,who has come to the rescure and helped me so much time and time again.

Same concept worked on my webpage first time.

Thankyou =)

PS: I was just wondering what is the different between using isset and just $_POST[] because i was reading at php.net and couldnt understand anything but only if you wanted to pass a variable?


:) You are welcome! I am not a guru! There are sooooo many things that I am not aware of.

isset() checks whether a variable is set, has a value (even null) in it. So, this would pass the value of that variable, only if its set.

} else {
  echo "Name is not set.";

As I said, If you assign null to a variable and check if it is set, it would return true.

echo "X is set";
} else {
echo "X is not set.";

In this case, it returns X is set, even though it doesn't have any value.



Ahhh ok Thankyou once again, off to read my other thread that you answered =P


Can u please give me whole code for multiple images uploading in php.. i have tried.. but its not working... plz plz help me.. its very urgent.. plz reply as soon as possible.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.