How do I check if a directory is writeable in PHP?

前端 未结 10 1600
别跟我提以往
别跟我提以往 2021-01-01 08:07

Does anyone know how I can check to see if a directory is writeable in PHP?

The function is_writable doesn\'t work for folders.

Edit: It doe

10条回答
  •  自闭症患者
    2021-01-01 08:57

    You may be sending a complete file path to the is_writable() function. is_writable() will return false if the file doesn't already exist in the directory. You need to check the directory itself with the filename removed, if this is the case. If you do that, is_writable will correctly tell you whether the directory is writable or not. If $file contains your file path do this:

    $file_directory = dirname($file);
    

    Then use is_writable($file_directory) to determine if the folder is writable.

    I hope this helps someone.

提交回复
热议问题