0

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

what do u thik about something like this valums.com/ajax-upload , what sulotion was used ?
@Chameron it says on the front page An older ajax upload plugin, which only used iframe for uploads...
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 yup, sounds like the way to go. However, the user must select the file in any case, you can't set the path programmatically.
@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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.