链接到根目录外的文件

链接到根目录外的文件

本文介绍了如何 URL 链接到根目录外的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

所以我有一个文件上传器,它允许人们将文件上传到服务器,然后通过 URL 下载它们.

So i have a file uploader that allows people to upload files to the server and then download them via a URL.

我想将上传的文件存储在根目录之外.(在名为 Uploads 的文件夹中从根目录向上一级)

I want to store uploaded files outside of the Root. (One level up from the root in a folder called Uploads)

代码片段

$server = "http://www.mysite.com";

$name = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
$size = $_FILES['file']['size'];

$destination = '../uploads/'. $random;
mkdir($destination);
move_uploaded_file($temp, $destination."/".$name);

$final = $server."/".$destination."/".$name;

这...

$destination = 'Uploads/' . $random ;

不起作用(找不到文件错误).($random 是顺便定义的..)

Didn't work (File not found error). ($random is defined by the way..)

推荐答案

简单的答案是建立一个符号链接到 ../Uploads 在 web 根目录:

The simple answer is to make a symbolic link to ../Uploads in the web root:

ln -s ../uploads Uploads

当然,这使上传目录可以通过网络访问.如果你想阻止上传目录被网络访问,不要创建符号链接,而是添加一个重写规则,将请求重定向到/Uploads/到一个将通过数据的 php 脚本,也许只有在检查某些条件之后(就像用户登录一样).

Of course this makes the uploads directory web accessible. If you want to prevent the uploads directory from being web accessible, do not make the symlink, but instead add a rewrite rule that redirects requests to /Uploads/ to a php script that will pass the data through, perhaps only after checking for certain conditions (like if the user is logged in).

这篇关于如何 URL 链接到根目录外的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:34