0

I am using below php to open pdf, it is working in Windows browser (eg. Windows Google Chrome), but failure to open by Mobile App (eg: Android Google Chrome), it will be download instead of open.

<?php
$com_no = $_POST['comno'];
$date = $_POST["date"];
$name_of_doc = $_POST["name_of_doc"]; 



// Store the file name into variable

$file = $com_no.'.pdf';
$filename = $date."_".$name_of_doc;
  
// Header content type
header('Content-type: application/pdf');
header('Content-disposition: inline; filename="'.$filename.'.pdf"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
  
// Read the file
@readfile($file);
  
?>

How shoule I rewrite it to support both open in the Windows and Mobile ? Thank you very much !

1 Answers1

1

TLDR: you can't program it as it is a browser configuration

If your PDF is opened in your desktop browser you have a configuration in your desktop-browser how to handle files of this type.

By default your browser should ask you what to do with data of that mime type.
You get the option:

  • open with browser
  • open with other application
  • store file

and maybe an option

  • [ ] always perform this action for files of this type

once you checked the option you no longer get bothered.


BTW:
even if you select open in browser, the file is downloaded in a temp folder to get shown.

Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38