我正在制作自己的网页。我有一个上传文件夹,我在其中存储上传的内容,如照片,pdf文件,文档等。我想限制访问该文件夹(不允许请求,如'http://www.mywebpage.com/uploads')。我试图创建包含"Deny from all
"记录的.htacces文件。现在这个文件夹的访问受限了,但又出现了其他问题——我的网站上所有的照片或其他文件都不见了。我猜,由于。htaccess文件,访问它们是不可能的。
有什么建议吗?
我使用WAMP与Apache 2.4.9和PHP 5.5.12如果有任何意义。
是否只拒绝访问www.yourpage.com/uploads
的目录列表?如果是,请尝试使用:
Options -Indexes
使用说明:
Options -Indexes
防止用户列出上传文件夹的内容。
首先在uploads文件夹中创建一个.htaccess
文件。
然后添加:
Options -Indexes
这将阻止目录列表,但您仍然可以通过使用直接URL看到图像。
像这样:
http://yourwebsite.com/photos/cute_cat.jpg
我在我所有的网站上都是这样做的:
创建一个名为give_file.php的文件
从受限制访问的文件夹中获取所有文件,并将它们返回给用户。
//select access permissions from database. Then figure out if user is allowed to access it. if user is allowed to access it, set $allowed to 1;
if($allowed)
{
$R=mysqli_query($Conn,'select * from users where resume=1 and id=' .$_REQUEST['uid']);
if(mysqli_num_rows($R)==0)
exit;
$l=mysqli_fetch_assoc($R);
$ln=$l['last_name'];
$fn=$l['first_name'];
$uniqueid=$l['uniqueid'];
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='".$ln .'_' . $fn . "_resume.pdf'");
readfile("resumes/resume_" . $uniqueid . '.pdf');
}
您可以找出每种图像类型需要的标题类型。通过这样做,您可以跟踪所有的使用统计数据,看看人们是否从其他地方访问网站,并做所有其他有趣的事情。