Im new to jQuery. I try to upload a jpg image file by using ajax method. But when I upload, it doesn't upload. Could anyone please help me to do this?
HTML
<form action="" method="POST" enctype="multipart/form-data"> <input type="file" name="image" id="image"/> </form>
jQuery
$('#submit').click(function() { var image=$('#image').val() $.post("upload.php",{image:image},function(data) { alert(data); }); } })
PHP
<?php $image=$_POST['image']; $imagename=date("d-m-Y")."-".time()."jpg"; $target_path = "uploads/".$imagename; if(move_uploaded_file($image, $target_path)) { echo 'moved'; } else { echo 'error'; } ?>