简体   繁体   English

使用Symlink的PHP / Linux Readfile路径

[英]PHP/Linux Readfile Path Using Symlink

I want to move my data directory outside of the web root. 我想将我的数据目录移到Web根目录之外。 I have file paths stored in my database and would like to be able to redirect looking for files through a symlink instead of having to change the saved paths. 我将文件路径存储在数据库中,并且希望能够通过符号链接重定向查找文件,而不必更改已保存的路径。

Example, currently I have a structure like this: 例子,目前我有这样的结构:

/root/webroot/data/file.ext

And my database path will be: /root/webroot/data/file.ext as well. 我的数据库路径也将是:/root/webroot/data/file.ext。 I'd like to move data outside of webroot so I have: 我想将数据移到webroot之外,所以我有:

/root/data/file.ext
/root/webroot/data -> root/data

Where /root/webroot/data is a linux style symlink to root/data. / root / webroot / data是到根目录/数据的linux样式符号链接。 I have set this up, but when I do a readfile on the previously stored path (/root/webroot/data/file.ext) it fails. 我已经进行了设置,但是当我在先前存储的路径(/root/webroot/data/file.ext)上执行readfile时,它将失败。 Ie I do this: 即我这样做:

readfile('/root/webroot/data/file.ext');

I get back: 我回来了:

Warning:  readfile(/root/webroot/data/file.ext) [function.readfile]: failed to open stream: No such file or directory in [file] on line ...

Is there anything I can do to help these paths resolve? 有什么我可以帮助您解决这些问题的方法吗?

Note: The permissions of the folders and files all match. 注意:文件夹和文件的权限全部匹配。 That of the symlink is root:root, from which it was created, but chown doesn't seem to work on it. 该符号链接的名称是root:root,它是从它创建的,但是chown似乎无法对其进行操作。

Where are you running the script from? 您从哪里运行脚本? If you are calling the directory without the leading slash: 如果调用目录时不带斜杠:

readfile('root/webroot/data/file.ext');

then you better make sure it is running in the same directory root is sitting in. However, if you are running this from webroot, you will need to update the readfile path to something like: 那么最好确保它在与根目录相同的目录中运行。但是,如果从webroot运行它,则需要将readfile路径更新为以下内容:

readfile('data/file.ext');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM