Scott B
Scott B

Reputation: 40157

How can I tell if file is writable from script?

My plugin needs to be able to write to the file system. Is it possible to query a known file for write permissions?

For example, my wordpress theme ships with a file called custom.css that i need write access to. When my theme first loads, I'd like to query this script to see if its writable, then echo the results to my theme.

Then in support session's, I can ask the user to visually check this setting to insure I have write permissions as expected (and eliminate that as the cause of a read/write issue).

Upvotes: 2

Views: 518

Answers (3)

Drewdin
Drewdin

Reputation: 1762

I'm probably way too late for this but there is "is_writable"

http://php.net/manual/en/function.is-writable.php

Upvotes: 2

Brad
Brad

Reputation: 163272

is_writable("yourfilename.txt")

http://php.net/manual/en/function.is-writable.php

For example...

if (is_writable('custom.css')) {
    echo "Success!  custom.css is writable";
} else {
    echo "Failure!! custom.css is not writable";
}

Upvotes: 6

Related Questions