fopen() fails to open stream: permission denied, yet permissions should be valid

前端 未结 2 849
小鲜肉
小鲜肉 2021-01-18 03:15

So, I have this error:

Warning: fopen(/path/to/test-in.txt) [function.fopen]: failed to open stream: Permission denied

Performing ls

相关标签:
2条回答
  • 2021-01-18 04:01

    Another reason of this error may be that the directory of file does not exist.

    I just add php code before fopen:

    if(!file_exists(dirname($file))) 
        mkdir(dirname($file));
    

    This help me out.

    0 讨论(0)
  • 2021-01-18 04:15

    Check if the user that PHP runs under have "X" permission on every directory of the file path.
    It will need it to access the file

    If your file is: /path/to/test-in.txt
    You should have X permission on:

    • /path
    • /path/to

    and read permission on /path/to/test-in.txt

    0 讨论(0)
提交回复
热议问题