Home > Backend Development > PHP Tutorial > php在服务器下创建文件权限的有关问题

php在服务器下创建文件权限的有关问题

WBOY
Release: 2016-06-13 13:13:18
Original
985 people have browsed it

php在服务器上创建文件权限的问题

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$res = fopen('/usr/local/asg/configs/meet.conf','a+');
fclose($res);

Copy after login

在本地机上如果meet.conf文件不存在,则可以创建,但在服务器上不行,用ls命令看了下,没有可写的权限,于是,在代码中加了判断
 
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
if(!is_writable('/usr/local/asg/configs')) {
    system('chmod 777 /usr/local/asg/configs');
}
$res = fopen('/usr/local/asg/configs/meet.conf','a+');
fclose($res);

Copy after login

运行后,依旧创建不了,再次改进了下
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
if(!is_writable('/usr/local/asg/configs')) {
    system('chmod 777 /usr/local/asg/configs');
}
system('touch /usr/local/asg/configs/meet.conf');

Copy after login

运行了下,仍旧不行,再次变通,用putty登陆到服务器,用命令行进入该目录,直接用touch创建,我叉,有用了,为什么在php文件里运行会不成功呢???


------解决方案--------------------
我认为你可以用php函数chmod 去完成这个操作

另外,要赋予php运行帐户有这个目录权限
------解决方案--------------------
if (!is_dir('/usr/local/asg/configs')) {
mkdir('/usr/local/asg/configs');
chmod('/usr/local/asg/configs',0777);
}
------解决方案--------------------
对于 php 没有权限的目录,怎么能用 php 赋予呢?

就好比你没有权限进国务院,那么你怎么装扮也是进不去的,除非你去找某个关系
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template