0

I'm using PDFMerger to merge PDFs but when i attempt to call the file that merges the pdfs merge.php by using ajax i get a 500 internal server error. When i type the file in the browser there is no 500 internal server error.

Here is the merge.php file.

$arr = $_REQUEST['idArray'];
include 'PDFMerger.php';

$pdf = new PDFMerger;

$i=0;
foreach($arr as $value) {
    $arr2[$i] = $value;
    $i++;
}

$filename = implode("-",$arr2);

$loop = 0;
$pdf->addPDF('samplepdfs/'.$arr2[0].'.pdf', 'all');

foreach($arr2 as $values) {
    if($loop>0) {
        $pdf->addPDF('samplepdfs/'.$arr2[1].'.pdf', 'all')
    }

    $loop++;
}
$pdf->merge('file', 'samplepdfs/'.$filename.'.pdf');

Here is the ajax function

$.ajax({
            url:"https://www.example.co.uk/wp-content/mpdf/examples/merge.php", //page to merge PDFs
            data: { idArray : id_array },
            type:'POST',
            success:function() {

}
});

Why do i get a 500 internal server error when using ajax with this file?

How do i solve this? I need to merge PDFs using ajax so i can print multiple PDFs at once.

Maximus2012
  • 1,799
  • 2
  • 12
  • 15
user892134
  • 3,078
  • 16
  • 62
  • 128
  • Do you have PHP error reporting turned on ? http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – Maximus2012 Apr 03 '15 at 16:57
  • Yes at the top of my PHP file i have `error_reporting(E_ALL); ini_set('display_errors', 1);` and no errors. – user892134 Apr 03 '15 at 16:59
  • the file works but not with an ajax call? – user892134 Apr 03 '15 at 17:00
  • I think your foreach loop will become an infinite loop. – Maximus2012 Apr 03 '15 at 17:01
  • What do you intend to do with your $loop variable. I think there might be a simpler way to implement what you're trying to do here. – Maximus2012 Apr 03 '15 at 17:03
  • Are you sure the request is getting passed to your merge.php file? Try var_dump($arr) and see what you get. – Maximus2012 Apr 03 '15 at 17:05
  • I'm using PDF Merger `https://pdfmerger.codeplex.com/` the $loop variable is just to determine the 1st,2nd,3rd,4th pdf files etc – user892134 Apr 03 '15 at 17:06
  • Try changing $pdf->addPDF('samplepdfs/'.$arr2[1].'.pdf', 'all') to $pdf->addPDF('samplepdfs/'.$arr2[$loop].'.pdf', 'all') – Maximus2012 Apr 03 '15 at 17:08
  • tried both of those suggestions. i check chrome development tools and the query string parameters are `idArray[]:12562`,`idArray[]:12561` but still 500 internal server error? – user892134 Apr 03 '15 at 17:17
  • Can you post the error detail form the server? you can use chrome's dev tools and see `network` tab, click on your ajax call which return 500, if you have turned on all error, you should still see some error text when 500 . and you can install `xdebug` to see more error info. – at15 Apr 03 '15 at 17:29
  • I've checked the network tab only error code i see is `Status Code:500 Internal Server Error` and no response data. – user892134 Apr 03 '15 at 17:34
  • Simplify the PHP right down to a simple response, then progressively build it back up and see when it breaks. – Roamer-1888 Apr 03 '15 at 18:18
  • I'm having the same issue; was anyone able to resolve this issue? – olimits7 Apr 21 '15 at 16:50

0 Answers0