0

这是我下载文件的代码:

假设我想下载pdf,所以

$file = 'Dev-TipsTricks.pdf';
$mime_type = 'application/pdf';
header("Content-type: $mime_type");
header("Content-disposition: attachment; filename=$file");
ob_clean();
flush(); 
readfile('wp-content/uploads/'.$file);
exit;

但是下载后当我尝试打开它时说: 在此处输入图像描述 我也尝试过 docx & 再次:

在此处输入图像描述

虽然文件内容是正确的并且在上传文件夹中它是正确打开的,但我也尝试了我的gif 图像代码,但它说:

在此处输入图像描述

4

1 回答 1

1

Well, if you are trying to send a PDF, you should also make sure to have the right extension (see the first screenshot, where you try to open it with Word).

For the second screenshot: try opening the file in a text editor, or comment out the "Content-disposition" header to check whether the readfile command is actually working properly. (maybe the path to the file is incorrect)

于 2013-04-05T13:07:17.313 回答