php输出错误信息和改变文件模式

One:Before you go to fix an error, it would be nice to know, which error to fix.
Add these lines at the top of your script and then try again


ini_set('display_errors',1);
<!-- lang: php -->
error_reporting(E_ALL);

PHP will tell you, what is the problem

for example:Warning: fopen(file/testFile.txt): failed to open stream: Permission denied in /home/suiyc/workspace/sycPro/createFile.php on line 9 can't open file

Two: Can the file is writable? we can use the next code to see if the file is writable.


echo var_dump(is_writable('file/sales.csv'));  // file path and file name

Three:change the file mod


<?php
<!-- lang: php -->
// 所有者可读写,其他人没有任何权限
<!-- lang: php -->
chmod("test.txt",0600);
<!-- lang: php -->

<!-- lang: php -->
// 所有者可读写,其他人可读
<!-- lang: php -->
chmod("test.txt",0644);
<!-- lang: php -->

<!-- lang: php -->
// 所有者有所有权限,其他所有人可读和执行
<!-- lang: php -->
chmod("test.txt",0755);
<!-- lang: php -->

<!-- lang: php -->
// 所有者有所有权限,所有者所在的组可读
<!-- lang: php -->
chmod("test.txt",0740);
<!-- lang: php -->
?> 

你可能感兴趣的:(php输出错误信息和改变文件模式)