0

header("Content-Type: application/octet-stream");

$file = $_GET["file"] .".pdf";
header("Content-Disposition: attachment; filename=" . urlencode($file));   
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");            
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp))
{
    echo fread($fp, 65536);
    flush(); // this is essential for large downloads
} 
fclose($fp); 




<FilesMatch "\.pdf$">
ForceType applicaton/octet-stream
Header set Content-Disposition attachment
</FilesMatch>

<a target="_blank" href="//site/file.pdf">Whitepaper</a>

Вот такой код он открывает и начинает скачивание как сделать просмотр? Пробывал как в примере ниже ничего не работает он просто скачивается. Сайт на wordpress

2 ответа 2

1

Если по клику начинается скачивание файла вместо открытия, то скорей всего сервер отдает заголовок:

Content-Type: application/octet-stream

чтобы открылся просмотр pdf в окне браузера сервер должен вернуть

Content-Type: application/pdf

Если файл отдается скриптом на стороне сервера, то надо реализовать в нем выбор правильного заголовка в зависимости от типа файла

0

Как открыть файл pdf в новой вкладке для чтения?

Гугл подсказывает, что вам надо поменять attachment

header("Content-Disposition: attachment; filename=" . urlencode($file)); 

на inline

header("Content-Disposition: inline; filename=" . urlencode($file)); 

соответственно и здесь тоже:

<FilesMatch "\.pdf$">
ForceType applicaton/octet-stream
Header set Content-Disposition inline
</FilesMatch>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.