0

The url will load the pdf document

https://riverside.iqm2.com/sameer/FileOpen.aspx?Type=14&ID=2157&Inline=True
but when i pass this url into header() chrome is throwing the following error failed to load pdf document
.
$filename = 'https://riverside.iqm2.com/sameer/FileOpen.aspx?Type=14&ID=2157&Inline=True';
header('Content-Type: application/pdf');
header('Content-Description:inline;filename="'.$filename.'"');
header('Content-Transfer-Encoding:binary');
header('Accept-range:bytes');
@readfile($filename);

i expect to download the pdf but the output is failed to load pdf document

Sameer Mohd
  • 11
  • 1
  • 5
  • the url you use probably use some internal process to provide actual url for the pdf, while in your php, it looks for the direct link – Vishwa May 06 '19 at 07:05
  • how to can implement the internal process using php – Sameer Mohd May 06 '19 at 07:09
  • This does not appear to have anything whatsoever to do with `xpath` - please tag responsibly, not just “whatever”. – 04FS May 06 '19 at 08:33
  • The error mentioned in comments, _“Object reference not set to an instance of an object.”_ does not appear to be a PHP error message to begin with - but the actual response you are getting from that remote site. So it is probably missing some “input” - could be something trivial like a proper User-Agent header send with the request. – 04FS May 06 '19 at 08:34

1 Answers1

0

Check out this answer: PHP readfile vs. file_get_contents

Also as of readfile manual:

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.