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 does work. See the accepted answer.
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: Then use is_writable($file_directory) to determine if the folder is writable.
The is_writable() function checks whether the specified filename is writable. Note: The result of this function is cached. Use clearstatcache() to clear the cache.
The chmod() function in PHP is an inbuilt function which is used to change the mode of a specified file to a specific mode given by the user. The chmod() function changes the permissions of the specified file and returns true on success and false on failure.
Yes, it does work for folders....
Returns TRUE if the filename exists and is writable. The filename argument may be a directory name allowing you to check if a directory is writable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With