$file_path = 'http://www.ifcmarkets.ru/pdf/forexbook/en/Forex_Trading_Strategies.pdf'; header('Content-Type: text/html; charset=utf-8'); function fileRandLine($file) { $f = fopen($file, "r"); while (!feof($f)) { $line = fgets($f); echo $line; } fclose($f); } echo fileRandLine($file_path); 

On the screen there are some kind of cracks.

Guys what am I doing wrong And is my code optimal or is there a better way?

Thank.

  • Use readfile () + header (). - Visman
  • @Visman Add please the working version of your proposal - user216109
  • It is believed that pdf is encoded as something else, and so it does not output. Although I could be wrong. - SLy_huh
  • @Visman combined with your answer. - Alexey Prisyazhnyy

1 answer 1

It is necessary to prompt the browser that you do not give the text (text / html), but pdf.
Plus using readfile will be much easier on resources.

full answer:

 $file_path = 'http://www.ifcmarkets.ru/pdf/forexbook/en/Forex_Trading_Strategies.pdf'; header('Content-Type: application/pdf'); readfile($file_path);