Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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文件下载不工作_Php_Html_Download - Fatal编程技术网

PHP文件下载不工作

PHP文件下载不工作,php,html,download,Php,Html,Download,我已经浏览了一些关于PHP文件下载的帖子,我没有找到任何解决方案 当我使用MAMP并运行.php文件时,它会完美地下载该文件。当我把它上传到我的网页服务器时,它会下载download.php文件,而不是我想让人们下载的pdf文件 我不知道是什么问题 下面是我的代码:download.php <?php $file_name = "BrianDaubCV.pdf"; $file_url = 'https://s3.amazonaws.com/www.briandaubdesign.com/d

我已经浏览了一些关于PHP文件下载的帖子,我没有找到任何解决方案

当我使用MAMP并运行.php文件时,它会完美地下载该文件。当我把它上传到我的网页服务器时,它会下载download.php文件,而不是我想让人们下载的pdf文件

我不知道是什么问题

下面是我的代码:download.php

<?php
$file_name = "BrianDaubCV.pdf";
$file_url = 'https://s3.amazonaws.com/www.briandaubdesign.com/download.php' . $file_name;
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"".$file_name."\""); 
readfile($file_url);
?>

resume.html

<a href="download.php">Download a copy of my resume (PDF)</a>


检查一下这个。它现在正在工作。我添加并更正了一些行

$file_name = "BrianDaubCV.pdf";
$file_url = 'https://s3.amazonaws.com/www.briandaubdesign.com/download.php' . $file_name;
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=".$file_name); 
header('Pragma: public');
readfile($file_url);

尝试将
放在php文件扩展名末尾的URL中,如下所示:
$file\u URL='1!'https://s3.amazonaws.com/www.briandaubdesign.com/download.php?' . $文件名您的站点将php文件视为html。您需要对web服务器配置进行一些操作,因此pdf的内容类型是
application/pdf
DevZer0是正确的。我尝试了您的链接,得到了实际的PHP代码,如果您的Web服务器设置为处理PHP文件,则不会出现这种情况。