2013-06-21 75 views
0

我已經瀏覽了PHP文件下載中的幾個主題,並且沒有找到任何解決方案。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> 

Here is the website

+3

嘗試把''在URL中的PHP文件擴展名像這樣的結尾:? '$ FILE_URL =「https://s3.amazonaws.com/www.briandaubdesign.com/download.php ? 。 $ file_name;' – Seeker

+2

您的網站將php文件視爲html。您將需要使用web服務器配置 – DevZer0

+0

也爲PDF內容類型是'application/pdf' – Gohn67

回答

0

檢查與此有關。它正在工作。我已經添加並更正了一些行。

$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);