Results 1 to 8 of 8

Thread: Multiple file uploads

  1. #1
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Multiple file uploads

    Hi,

    I'd need to build a "frontend" for instant uploading of multiple files. The PHP backend for handling the upload is pretty easy (iterating thru $_FILES['blah'.$x] in a loop).

    The frontent part is much more difficult though. Of course I can offer upload in series of perhaps five files, yet I know that my "employer" wants rather unlimited serialization (20+).

    So the question is: how do I store content of a file within, say, an array consisting of names, file contents and descriptions without resubmitting the form- but rather inserting to an array via external (like pop up window) form. Can you recommend any script that would take care of that?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I believe one can use an element array:
    Code:
    <form action="processor.php" method="post" enctype="multipart/form-data">
      <input type="file" name="uploads[]">
      <input type="file" name="uploads[]">
      <input type="file" name="uploads[]">
    </form>
    ... then access the elements as normal, but getting an array:
    Code:
    for($i = 0; $i < count($_FILES['uploads']); ++$i) {
      // Do things with $_FILES['uploads'][$i]
    }
    However, I've never done this. If it works, it will likely make your front-end code a lot simpler.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That was in deed my first though, yet my friend, whom I'll do the frontend for (image gallery), will usually upload 20 or more images, all with descriptions, author name, etc, etc... having 20 file fields isn't the answer, neither for him, nor me- I saw it done in webmail systems so I might try to reverse engineer one, though I bet it won't be easy thing to do- and secondly, problematic as copyright goes.

    However I just had "gold thought": how about build a javascript object consisting of the above fields? YES, That's it! Let's say I add a button that will add entire compound, but with different input IDs. Using my nice "show/hide" code, I can then "minimize" the "compounds" while new ones are added

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Oh, I see what you're saying now -- the same sort of feature that can be seen with this forum's attachment feature. This is accomplished by uploading each individual file in a separate request, and appending them to a list of files.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yep, almost the way I'd like to, and pretty enough for the job, instead though I first set up to upload each and every file in one shot- basically it's about my friend filling out the descriptions of images and letting entire series upload on server while he goes out/to sleep.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Unfortunately, that's not possible without simply having reams of file inputs. The value of a file input cannot be accessed or modified for security reasons, so it's not possible to store it anywhere.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    however, as you suggested, one can have multiple file inputs, and they can be added on the fly too, so that's not a big obstacle.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Indeed.
    Code:
    <form action="uploader.php" method="post" enctype="multipart/form-data">
      <div id="upl">
        <input type="file" name="uploads[]">
      </div>
      <input type="button" onclick="var e = document.getElementById('upl').appendChild(document.createElement('input')).type = 'file'; e.name = 'uploads[]';" value="Add file">
      <input type="submit" value="Upload">
    </form>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •