【发布时间】:2015-09-12 03:10:16
【问题描述】:
我正在开发文件共享服务,我尝试制作下载代码,但只显示一个白页!
这里是down.php的代码
<?php
$var = $_GET["fid"];
$fr = 'realname.txt'; //fake file name.
$filepath = '/home/user32222/public_html/parafile/'.$var.'/filestorage/downloadthisfile.txt' //In this case, file extension is txt but I want to download file with any extension even file extension is nothing
//I tried these codes but it not worked!!
/*header('Pragma: public'); // required
header('Expires: 0');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$fr\"");
header('Content-Length: ' . filesize($filepath));
readfile($filepath);*/
$size = filesize($filepath);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $fr); //Download Client Program think file's name is realname.txt ($fr)
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);
?>
【问题讨论】:
-
您忘记了
$fr = 'realname.txt之后的报价。'/home/user32222/public_html/parafile/'.$var.'/filestorage/downloadthisfile.txt'之后也缺少分号 -
@PHPglue 哦,我错过了 ' 和 ;。但是现在不行了……
-
打开错误报告看看 PHP 抛出了什么样的错误呢?到时候解决起来会容易很多!!!