PHP windows create hidden files

Is it possible to create hidden files / folders on windows using php (xampp)? And if so, how?

+4
source share
3 answers

A file in Windows is hidden if it has a hidden attribute. There is no built-in function for this, so you need to use system / exec to execute the application. Like this:

$file = 'test.txt'; system('attrib +H ' . escapeshellarg($file)); 

This will set the hidden flag (+ H) to test.txt.

+9
source

You can call attrib :

 $filename = 'c:\\some\\file.txt'; exec('attrib +h '.$filename); 
+2
source
 // 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 / ...

0
source

Source: https://habr.com/ru/post/1338891/


All Articles