I need to get ajax to send the location of a file to a php file, modify the file using imagemagick and return a true or false (if true, only extension changes). I thought I had it but I keep getting the following error. I checked the values of the variables i'm passing along and they all have the needed values. I checked a lot of other peoples code and mine looks the same as theirs. I have no idea where it goes wrong.
500 internal server error
Ajax:
var data_string = 'file_name=' + file_name + '&ext=' + ext + '&path=' + imagePath;
// console.log(data_string);
if (ext = ".pdf") {
$.ajax({
type: 'POST',
url: '../wp-content/gravity_forms_imagemagick.php',
data: data_string,
succes: function(data) {
console.log(data);
},
error: function() {
console.log("We failed you, Master");
}
});
}
PHP:
<?php
if(isset($_POST['file_name']) && isset($_POST['ext']) && isset($_POST['path'])) {
// Assemble full file url
$url = $_POST['path'] . $_POST['file_name'] . $_POST['ext'] . '[0]';
// Create Imagick class
$image = new Imagick($url);
// Set resolution
$image->setResolution(300, 300);
// Set new file format
$image->setImageFormat("png");
// Create png from pdf.
$image->writeImage($_POST['path'] . $_POST['file_name'] . '.png');
$succes = true;
echo json_encode($succes);
} else {
$succes = false;
}
?>