做了一个php下载页面,用到readfile(filepath)or die("File not found.");总是提示文件找不到。
下载文件相对于down.php在 ./admin/Upload 下,而我在down.php中用到的路径 filepath 是./admin/Upload/xxx.xxx
请问文件路径存在问题吗?应当怎样呢?
下载文件相对于down.php在 ./admin/Upload 下,而我在down.php中用到的路径 filepath 是./admin/Upload/xxx.xxx
请问文件路径存在问题吗?应当怎样呢?
<?php
$file_path=$_GET["path"];
$file_name=$_GET["name"];
//$fp=fopen($file_path,"r");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file_path));
header("Content-Disposition: attachment; filename=".$file_name);
readfile($file_path) or die("File not found.");
//echo fread($fp,filesize($file_path));
//fclose($fp);
?>
文件结构:
down.php
./admin/Upload/xxx.xxx
为什么文件明明存在却下载不下来,下载下来的文件里只有提示File not found.
$file_path=$_GET["path"];
$file_name=$_GET["name"];
$file_name=$file_path.$file_name;
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file_name));
header("Content-Disposition: attachment; filename=".$file_name);
readfile($file_name) or die("File not found.");
?>
file_path=$_GET["path"];
$file_name=$_GET["name"];
$fp=fopen($file_path,"r");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file_path));
header("Content-Disposition: attachment; filename=".$file_name);
//readfile($file_path) or die("File not found.");
echo fread($fp,filesize($file_path));
fclose($fp); 用fopen()呢?
用fopen()一样的啊。也是提示找不到文件。
本地测试好像没问题,传到服务器上总是file not found.