PHP windows create hidden files

你说的曾经没有我的故事 提交于 2019-12-19 03:41:31

问题


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


回答1:


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

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

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




回答2:


You could call attrib:

$filename = 'c:\\some\\file.txt';
exec('attrib +h '.$filename);



回答3:


// 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

Hints:
Replacing '/' with '\' is important as the shell command (attrib) is not as tolerant to slashes as PHP is.
$res is unset first because exec() appends to any existing value.

If you are looking for a way to set a file to read-only that will work on Windows AND *nix, then have a look at my answer to this other question: https://stackoverflow.com/a/27127640/430742



来源:https://stackoverflow.com/questions/4935614/php-windows-create-hidden-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!