I have an HTML form that I am trying to upload an image through.
<form id="imageform" method="post" enctype="multipart/form-data" action='upload.php'>
Upload image <input type="file" name="file" id="file" />
</form>
<div id='preview'>
</div>
I want to use JavaScript to upload run upload.php
, so the page does not have to refresh. I then want to display the output in #preview
.
$(document).ready(function() {
$('#file').live('change', function() {
$("#preview").html('');
$("#preview").html('Uploading...');
$.post("upload.php",$("#imageform").serialize(), function(data){
$("#preview").html(data);
});
});
});
However, I get many errors like these within the div. I know that the data isn't being sent through, but how can I fix it?
Notice: Undefined index: file in /path/upload.php on line 14
I've searched through things on Google, but I have been receiving the same issue.