i'm trying to upload image using ajax on file image name changing but i can't get the $_FILES["InputUploadFileImage"]["tmp_name"];
on the server side my code.
JQuery Code
$('#InputUploadFileImage').change(function() {
var FilePath = $('#InputUploadFileImage').val();
var FileSize = this.files[0].size;
$.ajax({
type: "POST",
async: true,
dataType: "json",
url: ajaxurl,
data: ({
type: "POST",
action: 'Ajax_ChangingProfileImage',
FilePath: FilePath,
FileSize: FileSize
}),
success: function (response) {
if (response.Message === 'ImageSuccessfullyUploaded') {
alert('Image Successfully Uploaded.');
$('#imgUserImage').image_src = FilePath;
console.log(response.FilePath);
} else {
alert('Image was not uploaded successfully.');
$('#imgUserImage').image_src = FilePath;
console.log(response.FilePath);
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
});
PHP Code
function Ajax_ChangingProfileImage() {
$FileTmpPath = $_FILES["InputUploadFileImage"]["tmp_name"];
$FileSize = $_POST['FileSize'];
$FilePath = $_SERVER['DOCUMENT_ROOT'] . "restronaut/wp-content/uploads/UsersImages/1.jpg";
$IsUploaded = move_uploaded_file($FileTmpPath ,$FilePath);
if ($IsUploaded) {
$response['Message'] = 'ImageSuccessfullyUploaded';
$response['FilePath'] = $FilePath;
} else {
$response['Message'] = 'ImageNotSuccessfullyUploaded';
$response['FilePath'] = $FilePath;
}
header('Content-Type: application/json');
echo json_encode($response);
die();
}
please any help and many thanks in advance..