0

I am using PDFMerger.php to merge my PDF files perfectly but when I try to make an interface for it, I keep getting a syntax error on the last line.

The original code (Is it possible to edit this code to work with my interface instead of what I have created? ):

<?php
include 'PDFMerger.php';
$pdf = new PDFMerger;
$pdf->addPDF('samplepdfs/one.pdf')
    ->addPDF('samplepdfs/two.pdf', '1-2')
    ->addPDF('samplepdfs/three.pdf', 'all')
    ->merge('download', 'TEST2.pdf');
    //REPLACE 'file' WITH 'browser', 'download', 'string', or 'file' for output options
    //You do not need to give a file path for browser, string, or download - just the name.
?>

Here is the interface in html:

<html>
<link href='login1.css' rel="stylesheet" type="text/css">
<body> 
<form action="merger.php" method="post" enctype="multipart/form-data" name="form1" id="formWrap"> 
  <h1>Compiler </h1><br /> 
  <div id="form">
   <br /> 
  <center>
  Upload your PDF files below: <br /> 
  <br /> 
  <input name="file[]" type="file" id="file[]" /> 
  <br /> 
  <input name="file[]" type="file" id="file[]" /> 
  <br /> 
  <input name="file[]" type="file" id="file[]" /> 
  <br /> 
  <input name="file[]" type="file" id="file[]" /> 
  <br /> 
  <br /> 
  <input type="submit" name="Submit" value="Merge!" /> 
  <br /> 
  <br /> 
  </center>
  </a> 
</form> 
</body> 
</html>

here is the new php file to merger the file from the interface and do checking:

<?php 
include 'PDFMerger.php';
$pdf = new PDFMerger;
if ($pdf['file']) { 
    foreach($pdf['file']['type'] as $key => $value) { 
    $ispdf = end(explode(".",$pdf['file']['name'][$key]));  
    $ispdf = strtolower($ispdf); 
        if ($value && $ispdf=='pdf') { 
            //upload each file to the server 
            $filename = $pdf['file']['name'][$key]; 
            $filename = str_replace(" ","",$filename); 
            $uploadfile = $uploaddir . $filename; 
            move_uploaded_file($pdf['file']['tmp_name'][$key], $uploadfile); 
   $pdf ->merge('download', 'TEST2.pdf');
} 
?> 

Here is the error text:

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\PDFMerger\merger.php on line 31
Zaito
  • 1
  • 2

1 Answers1

0

you have syntax error in code, missed 2 }

<?php 
include 'PDFMerger.php';
$pdf = new PDFMerger;
if ($pdf['file']) { 
    foreach($pdf['file']['type'] as $key => $value) { 
    $ispdf = end(explode(".",$pdf['file']['name'][$key]));  
    $ispdf = strtolower($ispdf); 
        if ($value && $ispdf=='pdf') { 
            //upload each file to the server 
            $filename = $pdf['file']['name'][$key]; 
            $filename = str_replace(" ","",$filename); 
            $uploadfile = $uploaddir . $filename; 
            move_uploaded_file($pdf['file']['tmp_name'][$key], $uploadfile); 
        }
    }
   $pdf ->merge('download', 'TEST2.pdf');
} 
?> 
Aniket Singh
  • 2,464
  • 1
  • 21
  • 32
  • Now I get this error Cannot use object of type PDFMerger as array – Zaito Aug 04 '15 at 07:16
  • Now see documentation of PHPMerger, and use appropriate methods with correct arguments, it will work for sure. – Aniket Singh Aug 04 '15 at 07:24
  • Aniket, thanks for the help. Could you help me one more time on the problem below? (I want to rename the uploaded files for merging) – Zaito Aug 05 '15 at 04:30
  • When your files are uploaded then you can rename of delete (unlink) them easily.. use `rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt");` and `unlink ( string $filename [, resource $context ] );` – Aniket Singh Aug 05 '15 at 09:46