Upload files via jquery $ .post
To submit an ajax form, I use this code:
<input type="file" class="file_1" id="file" /> - note: do not use the "FORM" tag
My jQuery code:
var file = $('#file').val(); $.post('form.php', {file:file}, function(data){}); And my PHP code:
if($_FILES["file"]["tmp_name"] != '') { $fileName = $_FILES["file"]["name"]; $fileTmpLoc = $_FILES["file"]["tmp_name"]; $fileType = $_FILES["file"]["type"]; $fileSize = $_FILES["file"]["size"]; } echo $fileName; But this code does not work
I think you canโt. However, there are some tools that imitate it. Check out this tutorial: http://hayageek.com/ajax-file-upload-jquery/
Or this question: Is it possible to use Ajax to upload files?