Rumah  >  Artikel  >  pembangunan bahagian belakang  >  php在服务器下创建文件权限的有关问题

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

WBOY
WBOYasal
2016-06-13 13:13:18959semak imbas

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);


在本地机上如果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);


运行后,依旧创建不了,再次改进了下
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');


运行了下,仍旧不行,再次变通,用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 赋予呢?

就好比你没有权限进国务院,那么你怎么装扮也是进不去的,除非你去找某个关系
Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya: PHP数组比较 求解解决思路 Artikel seterusnya: PHP学习系列6