Open a file in the browser served from PHP

ساخت وبلاگ

Vote count: 0

Simple question, probably been asked a million times but I've searched and am no closer to getting this to work.

I have a PHP script within the UserFrosting framework that serves a file to the user via their browser. I would like the file to open in their browser if they select 'Open' insteand of download.

Problem is, the only things that are opening properly are text files. Anything else (PDFs and JPGs tested so far) are just opening as a page of ASCII/garbled code instead of being interpreted as a PDF or an image.

Here's the code I'm using:

header('Content-Type: '. $mime);
header('Content-Length: ' . filesize($diskname));
header('Content-Disposition: inline; filename=' . $savename);
retu readfile($diskname);

$mime is the Mime type of the file set via a function, so could be application/pdf or image/jpeg for the files I'm trying to view so far.

Does anyone have any ideas why the files aren't opening properly?

asked 28 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 295 تاريخ : دوشنبه 31 خرداد 1395 ساعت: 16:44