关于PHP开启open_basedir后上传失败的问题

By testuser01 at 2015-12-16 • 0人收藏 • 282人看过

php配置里有开启这个选项,论坛放在/www/bbs下,upload_tmp_dir =/www/tmp,open_basedir的参数为/www但是上传文件失败,从error.log里得知是

PHP Warning:  Unknown: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/www:/www/bbs) in Unknown on line 0

请问论坛上传的文件缓存是否不受upload_tmp_dir限制直接存放在了/tmp?

2 个回复 | 最后更新于 2015-12-17
2015-12-16   #1

当然可以,但这显然是你的环境配置有问题。

如果权限设置没问题的话,那么就是你的open_basedir设置有问题,建议看完PHP官方对于这个参数的所有说明。


open_basedir string

Limit the files that can be accessed by PHP to the specified directory-tree, including the file itself. This directive is NOT affected by whether Safe Mode is turned On or Off.


When a script tries to access the filesystem, for example using include, or fopen(), the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to access it. All symbolic links are resolved, so it's not possible to avoid this restriction with a symlink. If the file doesn't exist then the symlink couldn't be resolved and the filename is compared to (a resolved) open_basedir .


open_basedir can affect more than just filesystem functions; for example if MySQL is configured to use mysqlnd drivers, LOAD DATA INFILE will be affected by open_basedir . Much of the extended functionality of PHP uses open_basedir in this way.


The special value . indicates that the working directory of the script will be used as the base-directory. This is, however, a little dangerous as the working directory of the script can easily be changed with chdir().


In httpd.conf, open_basedir can be turned off (e.g. for some virtual hosts) the same way as any other configuration directive with "php_admin_value open_basedir none".


Under Windows, separate the directories with a semicolon. On all other systems, separate the directories with a colon. As an Apache module, open_basedir paths from parent directories are now automatically inherited.


The restriction specified with open_basedir is a directory name since PHP 5.2.16 and 5.3.4. Previous versions used it as a prefix. This means that "open_basedir = /dir/incl" also allowed access to "/dir/include" and "/dir/incls" if they exist. When you want to restrict access to only the specified directory, end with a slash. For example: open_basedir = /dir/incl/


The default is to allow all files to be opened.

2015-12-17   #2

回复#1 @lincanbin :

好的,我再研究一下配置,谢谢。

登录后方可回帖

登 录
信息栏
购买PHP虚拟主机 / VPS

Carbon Forum是一个基于话题的高性能轻型PHP论坛

下载地址:Carbon Forum v5.0.1
QQ群:12607708(QQ我不常上)

donate

手机支付宝扫描上方二维码可向本项目捐款

Loading...