2

i have 3 file in directory.

1- jquery-1.8.3.min.js

2- index.html

3- addFile.php

and jquery-1.8.3.min.js is main jquery file.
index.html code is :

<html>
    <head>
         <script type="text/javascript" src="jquery-1.8.3.min.js"></script>
        <script type="text/javascript">
                $(document).ready(function () {
                    $("#uploadbutton").click(function () {
                        var filename = $("#tmppic").val();
                        $.ajax({
                            type: "POST",
                            url: "addFile.php",
                            enctype: 'multipart/form-data',
                            data: {
                                file: filename
                            },
                            success: function (result) {
                                alert(result);
                            }
                        });
                    });
                });
        </script>
    </head>
    <body>
        <div>
            <input type="file" name="tmppic" id="tmppic" />
            <input id="uploadbutton" type="button" value="Upload"/>
        </div>
    </body>
</html>

and addFile.php code is :

<?php
    //print_r($_FILES["tmppic"]);
    echo $_FILES["tmppic"]["type"];
    move_uploaded_file($_FILES["tmppic"]["tmp_name"], "uploads/" . $_FILES["tmppic"]["name"]);
?>

but this upload file not work.
thanks from helps.

4

1 Answer 1

1

I would suggest to use jQuery Form Plugin for ajax file upload.

http://www.malsup.com/jquery/form/

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

Comments

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.