0

HTML

<form id="uploadimage" action="" method="post" enctype="multipart/form-data">
        <div class="file-input btn btn-block btn-primary">
            + add files
            <input type="file" name="files" id="image_upload" >
        </div>
    </form>

JS

$('#image_upload').change(function(){
var formdata = $(this).parent().parent();
$.ajax({
     url: "/server.php", // Url to which the request is send
     type: "POST",             // Type of request to be send, called as method
     data: new FormData(formdata), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
     contentType: false,       // The content type used when sending data to the server.
     cache: false,             // To unable request pages to be cached
     processData:false,        // To send DOMDocument or non processed data file it is set to false
     success: function(data)   // A function to be called if request succeeds
     {
         alert(data);                          
     }
 });

Server.php

if(isset($_FILES["file"]["type"]))
        {
            echo "YES";
        }
        else echo "NO";

I've tryied to do different things but continue to get NO as answer. Any way to receive positive answer?

1 Answer 1

1

You're passing a jQuery object to your FromData constructor, which takes a form.
Expose the form from the jQuery object when you pass it

data: new FormData(formdata[0]), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
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.