Skip to content Skip to sidebar Skip to footer

Javascript Pass Input File To Php

I don't want to upload a file using Javascript, I just want to pass by Ajax the file to a PHP file, and in the PHP make the validations I want, plus use the move_uploaded_file func

Solution 1:

try this plugin

http://blueimp.github.io/jQuery-File-Upload/

$('#fileupload').fileupload({
    dataType: 'json',
    done: function (e, data) {
        $.each(data.result.files, function (index, file) {
            $('<p/>').text(file.name).appendTo(document.body);
        });
    }
});

Solution 2:

You can not upload files via AJAX. Usual way is to set the target of your form to a hidden iframe. Something like this.

<form target="myHiddenIframe" method="post" enctype="multipart/form-data">
    //your form elements here. 
</form>
<iframe name="myHiddenIframe"id="myHiddenIframe" style="display: none;" />

Submit the form to achieve what you want.

Post a Comment for "Javascript Pass Input File To Php"