2011-02-08 73 views
4

是否有可能使用PHP(xampp)在窗口上创建隐藏的文件/文件夹? 如果是这样,怎么样?PHP窗口创建隐藏文件

+0

隐藏什么或谁? – rik 2011-02-08 16:37:20

回答

9

的文件在Windows中,如果它具有隐藏属性,在其上设置隐藏。没有内置函数来执行此操作,因此您需要使用system/exec来执行attrib应用程序。像这样:

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

这将在test.txt中设置隐藏(+ H)标志。

2

你可以称之为attrib

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

提示:
更换“/”与“\”是作为外壳命令(ATTRIB)重要的不是作为耐受斜线为PHP是。
$ res先被取消,因为exec()附加到任何现有的值。

如果你正在寻找一种方式将文件设置为只读,将工作在Windows和* nix,然后看看我的回答这个其他问题:https://stackoverflow.com/a/27127640/430742