down.php是一个PHP文件,它可以用来处理文件下载请求。下面是一个简单的down.php文件示例,用于处理文件下载请求:
<?php
// 获取要下载的文件路径
$file = $_GET['file'];
// 检查文件是否存在
if (file_exists($file)) {
// 设置响应头,告诉浏览器文件类型和大小,并指定文件名
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
// 将文件内容输出到浏览器
ob_clean();
flush();
readfile($file);
exit;
} else {
echo "文件不存在";
}
?>
在上述代码中,首先通过$_GET['file']获取要下载的文件路径。然后,通过file_exists()函数检查文件是否存在。如果文件存在,就设置响应头,告诉浏览器文件类型和大小,并指定文件名。接下来,使用ob_clean()和flush()函数清空输出缓冲区,并将文件内容输出到浏览器,最后通过exit()函数终止脚本执行。如果文件不存在,则输出"文件不存在"。
要使用down.php处理文件下载请求,可以将文件路径作为参数传递给down.php,例如:down.php?file=/path/to/file.ext。
上一篇:设置php脚本内存
下一篇:php访问文件未知
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站