我创建了一个表单,当单击包含的按钮时,应该打开一个下载对话框来下载某个文件。文件放在同一台服务器上。
我试着:
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=" . $file . '"');
其中$file为本地路径+文件名,例如c:'mypath'myfile.xls。但这行不通。它提供给我一个文件,但不是一个有效的文件。我还能怎么做呢?
注意:我写c:'是因为它还在我的本地机器上进行测试。
谢谢!
试试这个
header("Pragma: public", true);
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($file));
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
die(file_get_contents($file));
我认为file_get_contents()函数不再工作与PHP 5.0.3
试试这个:
<>之前$path = "http://www.example.com/files/";$filename = "abc.gif";标题("内容类型:图像/gif");标题("附加项:附件;文件名= " $ filename);标题("cache - control:私人");标题("X-Sendfile:"美元。路径);readfile(路径);退出;PHP在服务器端运行,无法在客户端下载文件。
上传文件到服务器,然后给出下载路径
路径必须从站点根目录引用…移动文件例:脚本路径:C:/wamp/www/test.php文件 C:/script.js然后:
if(file_exists('../../user.js'))
{
echo "OK";
}
还是个坏主意