session - PHP Combining Two PDFs Script Returns First Page Combined Twice -


i've got php script merges 2 pdf files. script works when pull 2 files directly server. point post 2 treat service , post 2 files base 64 encoded text , merge files , let receiving end download combined pdf.

when using post variables, mixed results. think stuck in cache or in session, i'm not familiar how correctly make happen.

when result incorrect, first pdf combined twice. started check if pdf1 = pdf2 , throw error, never happens when testing unless post same pdf. i've tried further tests in script, cannot identify point of error.

how else can debug this? else can try?

here's current script:

<?php require_once($_server['document_root'].'/pdfmerge/tcpdf/tcpdf.php'); require_once($_server['document_root'].'/pdfmerge/tcpdf/tcpdi.php');   class mergepdf extends tcpdi  {     public $files = array();      public function setfiles($files)     {         $this->files = $files;     }      public function concat()//from set assign example {     foreach($this->files $key=> $file) {         $pagecount = $this->setsourcedata($file);//setsourcedata used raw data         ($pageno = 1; $pageno <= $pagecount; $pageno++) {              $tplidx = $this->importpage($pageno);              $s = $this->gettemplatesize($tplidx);              $this->addpage($s['w'] > $s['h'] ? 'l' : 'p', array($s['w'], $s['h']));              $this->usetemplate($tplidx);         }         if($key>0){             if ($this->files[0] == $this->files[1]){             echo "duplicate file error"; //i cannot occur             die();             }                            }         unset($file);         unset($pagecount);     } }   }  //error_log("mergepdf called");  $pdf641 = $_post['pdf1']; $pdf642 = $_post['pdf2']; $outputtype = $_post['output'];   if ($pdf641 == $pdf642) {        echo "error: both files same";     error_log("mergepdf error: both files same!");     session_unset();     die(); }  /*  if (hash("sha256",$pdf641,false) == hash("sha256", $pdf642,false)) {         echo "error: both files same";         error_log("mergepdf error: both sha256 files same!");         die(); } */   $p1d = base64_decode($pdf641); $p2d = base64_decode($pdf642);  $pdf = new mergepdf(); $pdf->setfiles(array( $p1d, $p2d));  $pdf->concat();  $uuid = uniqid("pdf_",false);  if ($outputtype == "download") {     $pdf->output($uuid . '.pdf', 'i'); /*//d i*/  } else {     $out = base64_encode($pdf->output($uuid . '.pdf', 's')); //output 's' string      echo $out; }  ?> 


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -