Results 1 to 4 of 4

Thread: ajax form submission, but with a file input

  1. #1
    Join Date
    Jun 2008
    Posts
    53
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default ajax form submission, but with a file input

    Hey all, I have some code that I'm using to handle my data submission as an ajax form asynchronously, and all my data is passing fine, except I don't know how to make it work for a file, I don't have any code for it and I've been looking at google and haven't found anything, can someone help me find out what I need to add to handle my file input?

    code:
    Code:
    // Loop through form fields
        for (i=0; i < thisform.length; i++)
        {
             //Build Send String
             if(thisform.elements[i].type == "text"){ //Handle Textbox's
                      formdata = formdata + thisform.elements[i].name + "=" + escape(thisform.elements[i].value) + "&";
             }else if(thisform.elements[i].type == "textarea"){ //Handle textareas
                      formdata = formdata + thisform.elements[i].name + "=" + escape(thisform.elements[i].value) + "&";
             }else if(thisform.elements[i].type == "checkbox"){ //Handle checkbox's
                     formdata = formdata + thisform.elements[i].name + "=" + thisform.elements[i].checked + "&";
             }else if(thisform.elements[i].type == "radio"){ //Handle Radio buttons
                      if(thisform.elements[i].checked==true){
                         formdata = formdata + thisform.elements[i].name + "=" + thisform.elements[i].value + "&";
                      }
             }else{
                      //finally, this should theoretically this is a select box.
                      formdata = formdata + thisform.elements[i].name + "=" + escape(thisform.elements[i].value) + "&";
             }
    Obviously Ive totally left out the file part.
    How does it get handled into the php $_FILES file array?

  2. #2
    Join Date
    Jun 2008
    Posts
    53
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Or perhaps is it possible is a better question?

  3. #3
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Apparently, the only way (I could think of) that is possible is to use the iframe technique.

    You target the upload, to that of the iframe, and when the iframe has loaded, instruct the parent page to do somethings you want.

    You might find these links useful:
    http://www.openjs.com/articles/ajax/ajax_file_upload/
    http://www.ajaxf1.com/tutorial/ajax-...-tutorial.html
    http://www.webtoolkit.info/ajax-file-upload.html
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  4. #4
    Join Date
    Dec 2008
    Location
    Nigeria
    Posts
    95
    Thanks
    3
    Thanked 8 Times in 8 Posts

    Default

    I have tried that stuff too, to no avail, best thing is to use ur hidden iframe method, display a waiting gif....and if ur server can use perl, u can find some free perl scripts that will even show u the progress bar 'cos perl (not php) can access the posted raw data and determine the size of the file before upload, and can upload in chunks.....

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
  •