0

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;
 }
?>
Evergetic
  • 37
  • 1
  • 8
  • The reasons can be many. Are you able to turn on displaying PHP errors (see http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display )? If not, try at least putting something like "echo 'line XXX';" after each line to see on which line your code actually crashes. It will be probably one of these reasons: 1) ImageMagick not installed on server 2) not enough memory allowed for PHP to load and process the image 3) unable to write the result due to file permissions. – amik Apr 12 '17 at 13:21
  • I turned the errors on. But it's not displaying anything. My boss told me he had installed ImageMagick on the server so it should be good. We modify other pdf's and images and that seems to work fine. I had a file permission problem earlier that gave me a different errorcode but was fixed. – Evergetic Apr 12 '17 at 13:52
  • @amik I have now reduced the resolution to 100, 100. Write permissions shouldn't be a problem. The file gives an error on pdf files and normal image files. – Evergetic Apr 12 '17 at 16:12
  • on which line the script dies? try debugging it as I suggested in previous comment. – amik Apr 14 '17 at 14:45

0 Answers0