简体   繁体   中英

How to use "pdftotext" on multiple pdf files?

Can someone here can help me on my problem ? I have this code on displaying output of pdf file on web using pdftotext

include ( 'PdfToText-master/PdfToText.phpclass' ) ;

<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="pdf_file" multiple="multiple">
<input type="submit" name="SubmitButton"/>
</form>

if(isset($_POST['SubmitButton'])){
$pdf =  new PdfToText ($_FILES['pdf_file']['tmp_name']) ;
text =  $pdf -> Text; 
echo $text;
}

it works fine, But what im trying is to upload multiple files and display it on web all the files uploaded. I can't find any solution. Can you help me guys ? :(

PS: sorry my english is not that good. THank youuu!

where you upload multiple file. you will get the files in array.
Therefore, you need to loop over the tmp files

function show_pdf_text($file){
  $pdf =  new PdfToText ($file) ;
  $text =  $pdf->Text; 
  echo $text;
}

if(isset($_POST['SubmitButton'])){
 if(is_array($_FILES['pdf_file']['tmp_name'])){
 foreach($_FILES['pdf_file']['tmp_name'] as $temp){
     show_pdf_text($temp);
  }
 }else show_pdf_text($_FILES['pdf_file']['tmp_name']);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM