簡體   English   中英

在 HTML 文件中顯示帶有 PHP 的 PDF

[英]Display a PDF with PHP in HTML file

我想保護我的 PDF 的顯示:首先為用戶隱藏 PDF 的源鏈接,其次使 PDF 無法下載。
我在第一點,我用過:

<?php 
$file = "./src/file.pdf";
header("Content-type: application/pdf"); 
header("Content-Length: " . filesize($file)); 
readfile($file);
?>

這在沒有任何 HTML 的頁面上工作得很好,但如果我只添加:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>TEST</title>
</head>
<body>
  <div>
    <!-- Some elements -->
  </div>
  <div>
    <?php 
    $file = "./src/file.pdf";
    header("Content-type: application/pdf"); 
    header("Content-Length: " . filesize($file)); 
    readfile($file);
    ?>
  </div>
</body>
</html>

那根本行不通
那我該怎么辦? 因為我想要這個地方的PDF,被HTML包圍。

如果有人有解決方案,或者更多,隱藏PDF源鏈接的解決方案,其次使PDF無法下載。

我非常感謝您的時間和耐心!

正如 Ken Lee 指出的那樣,在調用 header 之前,您不能擁有任何header

<?php
    $file = "./src/file.pdf";
    header("Content-type: application/pdf"); 
    header("Content-Length: " . filesize($file));
?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>TEST</title>
</head>
<body>
  <div>
    <!-- Some elements -->
  </div>
  <div>
    <?php readfile($file); ?>
  </div>
</body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM