So, I am a little new to using AJAX, I just have a question or two.
When I select an image, everything goes according to plans, if I choose to remove that photo, rather then uploading it the size of the image comes back as 9, why is that?
Will it always be 9?
Am I safe to do a if(filesize == 9) { //stuff }
to tell if the user has removed the image before uploading?
Here is the javascript:
$("#chosenfile").change(function(){
var data;
data = new FormData();
data.append( 'file', new Blob([$( '#chosenfile' )[0].files[0]], {type:"image/jpg"}) );
$.ajax({
url: '/includes/uploadimage.php',
data: data,
processData: false,
contentType: false,
type: 'POST',
success: function ( data ) {
alert( data );
var json = JSON.parse(data);
console.log(json);
}
});
});
Here is uploadimage.php:
<?php
$Return = array();
$Return["status"] = "success";
$Return["image"] = "";
$file = $_FILES["file"];
$tmpName = $file["tmp_name"];
echo json_encode($Return);
?>
I am getting this in my console:
{"status":"success","image":{"name":"blob","type":"image\/jpg","tmp_name":"\/tmp\/phpHWiMwv","error":0,"size":9}}