Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to pass array of <input type='file'> with prototype.js

    hi to all

    I am unsing prototype.js for ajax. I am making a image/doc upload program. In which i am repeating the <input tpye='file'> option in a loop as desired by user. here's the code

    <?php
    for($i=1; $i<=$max_no_img; $i++){
    ?>
    <tr>
    <td>Document <?php echo $i ?></td>
    <td><input type="file" name="images[]" /></td>
    </tr>
    <?php } ?>

    Now i want to pass the values for these three files with the help of ajax but its not sending... the code is


    function upload_documents() {
    new Ajax.Request("upload_doc.php",
    {
    method: 'post',


    postBody: '&images='+ $F('images'),
    onComplete: upload_documentsResponse
    });
    }

    function upload_documentsResponse(req){

    $('show_per').innerHTML= req.responseText;
    }

    and further more i now have a requirement for only 3 uploads then i removed the loop, made 3 files input tag then den submitted with ajax.
    Now came another problem
    when i am echoing the files name with $_POST[] , it is printing the whole file name but when i am using

    $_FILES['images1']['name'] it not printing anyting I know tat $FILES is a multidimensional array so i even tried printing with foreach statement then too its not printing anything.

    Thanks in advance for any help........

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    AFAIK a HTTP request by javascript cannot perform an upload. The actual form must be submitted and the browser's form handling must perform the upload.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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