Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php下载pdf文件_Php_Pdf_Download - Fatal编程技术网

使用php下载pdf文件

使用php下载pdf文件,php,pdf,download,Php,Pdf,Download,我有PHP文件存储在我的服务器上,它们的名字在mysql数据库中,我想下载这些文件。我应该为相同的代码编写什么?我使用PHP作为编码语言。请帮助。 <?php $file = 'send_me.pdf'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('C

我有PHP文件存储在我的服务器上,它们的名字在mysql数据库中,我想下载这些文件。我应该为相同的代码编写什么?我使用PHP作为编码语言。请帮助。

<?php
$file = 'send_me.pdf';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}
?>
从字面上说,只需在存储的文件中创建一个链接

file_put_contents("PDFName.pdf", fopen("http://someurl/PDFName.pdf", 'r'));
在提问之前,你真的应该在网上展示你迄今为止所做的工作/研究成果!
这将从url下载文件PDFName.pdf,并将其放入脚本所在的目录中。

只需选择您的问题标题,右键单击并在google上单击搜索,您将在第一个链接上获得解决方案。@KevinNelson我正要使用您可能的副本来结束此问题,但OP的故事似乎更进一步:“他们的名字在mysql数据库中”-TBH,我“在围栏上”“这个问题。@Fred ii-,嗯……是的……也许我是因为这是一个没有更多细节的问题,他在哪些领域苦苦挣扎。我假设,因为他把名字放在数据库中,他知道如何把名字拿出来,而他只是不知道如何进行输出。DB query的另一个例子:@rugwed,我不是想打败你,但作为将来的参考,这可能会帮助你问一些不会被否决的问题: