tags:

views:

33

answers:

1

my 2form.php :

<script type="text/javascript" src="mootools.js"></script>
<script type="text/javascript">
    function test()
    {
        url = '2form.php';
        var ajax = new Ajax(url, {
            method: 'post',
            onComplete: function(response) {            
                document.getElementById('error_upload_logo').innerHTML = response;
            }
        });     
        ajax.request();
    }   
</script>
<?php
    if($_FILES)
    {
        echo "<div>";
        foreach($_FILES['name'] as $v)
        {
            echo $v."<br/>";
        }
        echo "</div>";
    }
    else
    { ?>
        <form action='' id='form1' name="form1" method="post" enctype="multipart/form-data">
            <input type="file" name="name"/>
            <input type="submit" name="submit" onclick='test(); return false;'/>
        </form>
<?php
    }
?>

<div id="error_upload_logo"></div>

if run code with out javascript , it 2form.php like simple php page, and

we can see information of $_FILES that was printed to scrreen

But if i have run with javascript by test() function ,

i don't get information in $_FILES ?

How to get $_FILES ? when click button run with javascript ?

i want to upload with ajax

+2  A: 

You can't do file uploads using AJAX because you won't have access to the local file.

The most common workaround is what the JQuery Form plugin does, creating a temporary iframe and doing a normal form submit into it.

The other alternative is using a Flash-based uploader like SWFUpload or Uploadify.

Pekka
what do u thik about something like this http://valums.com/ajax-upload/ , what sulotion was used ?
Chameron
@Chameron it says on the front page `An older ajax upload plugin, which only used iframe for uploads...`
Pekka
i viewed code , and see something like using js create a iframe with form upload , push pahtfile to input file and submit this form. I don't sure ? what do u think?
Chameron
@Chameron yup, sounds like the way to go. However, the user must select the file in any case, you can't set the path programmatically.
Pekka
yeah , but i still don't know how our can get $_FILES by ajax ?????
Chameron
@Chameron you can't, that is the whole point. You need to submit the form into the iframe to a normal PHP script. That script will have the $_FILES array available.
Pekka
yeah . I think so. get $_FILES by ajax is impossible. But I have to try to research it for my boss :)) . Thank you very much
Chameron