Hi so i want to create a specific error response through AJAX that will show if an image is too big, or an image is the wrong format? I just do not know how to do this with my separate php file or my AJAX call in my main index file.
Here is the AJAX call
$.ajax({
url: 'upload.php',
type: 'POST',
data: fd,
contentType: false,
processData: false,
success: function(result) {
console.log('Success!');
console.log(result);
location.reload();
},
error: function(xhr, status, error) {
if (xhr.status = "Error - 200") {
$("#error").append(`<p> The following file was to big to upload</p>`
}
var errorMessage = xhr.status + ': ' + xhr.statusText
console.log(errorMessage);
}
});
Here is my PHP file
$file = $_FILES['file'];
$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png', 'pdf');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 1000000) {
$fileNameNew = uniqid('', true) . "." . $fileActualExt;
$fileDestination = "../test/assets/images/" . $fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
}
} else {
return false;
}
};
I just do not know where i can set a specific variable that I can use to insert like a specific alert in my html? Thank you.