Uploading multiple Images through input type="file"

Thread Solved

Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Uploading multiple Images through input type="file"

 
0
  #1
Jan 12th, 2008
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['file[$index]']['name'] 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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Uploading multiple Images through input type="file"

 
0
  #2
Jan 12th, 2008
Can you show us your script ? What is the error that you are getting ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: Uploading multiple Images through input type="file"

 
0
  #3
Jan 12th, 2008
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:

  1.  
  2. switch($_POST['submit']) {
  3. case 'UPLOAD':
  4. now a whole bunch of code access variables and databases then
  5.  
  6. $file = $_FILES['file']['name'];
  7.  
  8. again a whole bunch of code
  9. }
  10.  
  11. <input type="file" id="file" name="file">
  12. <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['file[index]']['name']; using a for loop using 'index'.

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

Thanks Again, Regards X
Last edited by OmniX; Jan 12th, 2008 at 8:49 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Uploading multiple Images through input type="file"

 
1
  #4
Jan 12th, 2008
  1. <?php
  2. if(isset($_POST['submit'])) {
  3. for($i=0;$i<count($_FILES['fileupload']);$i++) {
  4. print $_FILES['fileupload']['name'][$i]."<br />";
  5. }
  6. }
  7. ?>
  8. <html>
  9. <body>
  10. <form name="upload" method="post" action="upload.php" enctype="multipart/form-data">
  11. <table>
  12. <tr><td>
  13. <input type="file" name="fileupload[]">
  14. </td></tr>
  15. <tr><td>
  16. <input type="file" name="fileupload[]">
  17. </td></tr>
  18. <tr><td>
  19. <input type="file" name="fileupload[]">
  20. </td></tr>
  21. <tr><td>
  22. <input type="file" name="fileupload[]">
  23. </td></tr>
  24. <tr><td>
  25. <input type="submit" name="submit">
  26. </td></tr>
  27. </table>
  28. </form>
  29. </body>
  30. </html>

This works for me!
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: Uploading multiple Images through input type="file"

 
0
  #5
Jan 12th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Uploading multiple Images through input type="file"

 
0
  #6
Jan 12th, 2008
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.

if(isset[$_POST['name'])){
$name=$_POST['name'];
} 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.

$x="";
if(isset($x)){
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.

Cheers,
Naveen
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

Re: Uploading multiple Images through input type="file"

 
0
  #7
Jan 13th, 2008
Ahhh ok Thankyou once again, off to read my other thread that you answered =P
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC