从php服务器下载文件时出现的问题
我为我的大学项目编写了一个脚本,它读取目录中的文件,并通过foreach循环对它们进行响应,它作为一个列表来执行,所以从php服务器下载文件时出现的问题,php,Php,我为我的大学项目编写了一个脚本,它读取目录中的文件,并通过foreach循环对它们进行响应,它作为一个列表来执行,所以 "<ul>"; //this ul is outside the foreach loop "<li><b>".$ftype.": ".$rows."</b> <ul> <li><
"<ul>"; //this ul is outside the foreach loop
"<li><b>".$ftype.": ".$rows."</b>
<ul>
<li><a href='?run=delete.$dir$rows'>Delete ".$ftype."</a></li>
<li><a href='?run=rename.$dir$rows'>Rename ".$ftype."</a></li>
<li><a href='?run=download.$dir$rows'>Download ".$ftype."</a></li>
</ul>
</li>";
"</ul>"; //this ending ul tag is outside the foreach loop
$ftype是一个变量集,取决于$rows是否为dir
if (is_dir($dir.$rows){
$ftype = "Folder";
} else {
$ftype = "File";
}
这是我的脚本的输出:
Folder: pics
Delete Folder
Rename Folder
Download Folder
File: screenshot (4).png
Delete File
Rename File
Download File
File: screenshot.png
Delete File
Rename File
Download File
File: screenshot_(2).png
Delete File
Rename File
Download File
File: screenshot_(3).png
Delete File
Rename File
Download File
Folder: trip
Delete Folder
Rename Folder
Download Folder
简而言之,我需要另一个php文件,其中包含一个开关,该开关检测“run”是什么,并对结果作出反应,因此当“run”设置为下载时,它使用设置为“run”的字符串。为了简单快速地解释这一点,我将举一个例子:
如果我点击“下载文件”获取“文件:screenshot.png”,运行设置为
?运行=下载。上传/admin@admin.com/screenshot.png so
下载。上传/admin@admin.com/screenshot.png
我在另一个php文件上所做的切换检查(substr($linkchoice,0,8))==“download”,因此如果run的第一到第八个字符等于download,则执行header(“位置:$linkchoice;内容类型:application/force download”);中断
我的问题是,当我单击“下载”时,会出现以下错误:
禁止访问强>
您没有访问请求对象的权限。它受读保护,或者服务器不可读
如果您认为这是服务器错误,请联系网站管理员
错误403
本地主机
Apache/2.4.17(Win32)OpenSSL/1.0.2d PHP/5.6.15
如果有人想看代码,请询问,我会把它放在github上
如果我的代码是错误的,请告诉我,以及如何修复它
此外,我还尝试使用其他一些下载代码,让我下载具有给定扩展名的文件,但当我打开它们时,假设一张图片在windows photo viewer中打开,但它说windows photo viewer不支持文件类型…什么是
$linkchoice
以及什么是admin@admin.com/screenshot.png
?$linkchoice=$\u GET['run'];及admin@admin.com是uploads文件夹中的一个文件夹,screenshot.png文件本身就是一张图片
Folder: pics
Delete Folder
Rename Folder
Download Folder
File: screenshot (4).png
Delete File
Rename File
Download File
File: screenshot.png
Delete File
Rename File
Download File
File: screenshot_(2).png
Delete File
Rename File
Download File
File: screenshot_(3).png
Delete File
Rename File
Download File
Folder: trip
Delete Folder
Rename Folder
Download Folder
switch($linkchoice){
case (substr($linkchoice, 0, 8)) == "download":
header("Location: $linkchoice; Content-type: application/force-download");
break;//I have cases for the rename and delete but those aren't relevant to my problem