3raser Posted October 28, 2012 Share Posted October 28, 2012 I have index.php: http://paste2.org/p/2394784 And then I have a file called post.php - Is there any way to get the file from the input field in index.php to go through the AJAX request? I attempt something like so: when the file is selected in the html field, set the var file equal to it image.change(function(){ extension = image.val().split('.')[1]; if(extension != 'png' && extension != 'jpeg' && extension != 'bmp' && extension != 'gif'){ image.val(''); displayError('#image', 'That file extension is not allowed.'); }else{ file = this; } }); Then when the user is done, and they click submit - send the file through POST: $.ajax({ type: "POST", url: "post.php", data: { t: title.val(), c: content.val(), image: file} }).done(function(msg) { alert(msg); if(msg != "success"){ split = msg.split(','); displayError(split[0], split[1]); }else{ alert(msg); } }); Link to comment https://forums.phpfreaks.com/topic/270009-send-file-from-html-form-to-postphp/ Share on other sites More sharing options...
3raser Posted October 30, 2012 Author Share Posted October 30, 2012 Any ideas? Link to comment https://forums.phpfreaks.com/topic/270009-send-file-from-html-form-to-postphp/#findComment-1388867 Share on other sites More sharing options...
Mahngiel Posted October 30, 2012 Share Posted October 30, 2012 files aren't sent through post, they'r sent through php://input. you'll have to capture it at that end. check out this tutorial Link to comment https://forums.phpfreaks.com/topic/270009-send-file-from-html-form-to-postphp/#findComment-1388871 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.