Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 514
SeanDowney Avatar asked Sep 20 '08 20:09

SeanDowney


People also ask

How can I tell if a directory is writable?

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.

What is the purpose of using Is_writable () function?

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.

How can I give permission to a folder in PHP?

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.


1 Answers

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.

like image 179
DGM Avatar answered Sep 29 '22 23:09

DGM