// set HIDDEN attribute of file on Windows $file = 'path/to/file.ext'; $file = str_replace('/', '\\', $file); unset($res); exec('attrib +H ' . escapeshellarg($file), $res); $res = $res[0]; //$res contains result string of operation
Tips:
Replacing '/' with '\' is important because the shell command (attribute) is not as tolerant of slashes as PHP.
$ res is not set first because exec () is appended to any existing value.
If you are looking for a way to install a read-only file that will work on Windows and * nix, look at my answer to this other question: fooobar.com/questions/1338892 / ...
source share