html code here
<form id="upload_img_form" enctype="multipart/form-data">
<input id="add_picture" type="file" name="post_img" >
<span id="postbutton" >Post</span>
</form>
//I don't want to use the action at the form above, because the page would reload or refresh
I have done some of the research and knew the dataform in ajax or jquery may work for this problem. But I don't know how to retrieve the data once I use jquery method
javascript codes here
$('#postbutton').click(function(){
var formData = new FormData($('#upload_img_form')[0]);
$.ajax({
url: 'upload.php', //Server script to process data
type: 'POST',
//Ajax events
beforeSend: beforeSendHandler,
success: completeHandler,
error: errorHandler,
// Form data
data: formData,
//Options to tell jQuery not to process data or worry about content-type.
cache: false,
contentType: false,
processData: false
});
});
Basically, I don't know how to process the data in 'upload.php'
, and I have tried $_POST['formData']
and I need to get the parameter for move_uploaded_files($_FILES['file']['name'],$path)
in order to save the file to a specific path