我有以下内容file.php.我的PDF位于文件夹中file.php,并且其文件位于同一目录中.当我按下按钮时,PDF不是下载而是下载file.php.
<?php
if (isset($_POST['file_name'])){
$file= $_POST['file_name'];
header('Content- type: application/pdf');
header('Content-Disposition: attachament; filename: " .$files"');
readfile('files/'.$file);
exit();
}
?>
<form action="file.php" method="POST" >
<input name="file_name" value="cv.pdf" type="hidden">
<input type="submit" value="Download CV">
</form>
Run Code Online (Sandbox Code Playgroud)
不需要这一切.试试这个:
<a href="/files/yourfullPathOnTheServer.format" download>
Run Code Online (Sandbox Code Playgroud)
你可以用按钮替换一个href :)
| 归档时间: |
|
| 查看次数: |
264 次 |
| 最近记录: |