简体   繁体   English

PHP窗口创建隐藏文件

[英]PHP windows create hidden files

Is it possible to create hidden files/folders on windows using php (xampp)? 是否可以使用php(xampp)在Windows上创建隐藏文件/文件夹? And if it is, how? 如果是的话,怎么样?

A file in Windows is hidden if it has the hidden attribute set on it. 如果Windows中的文件设置了隐藏属性,则会隐藏该文件。 There is no built in function to do this, so you need to use system / exec to execute the attrib application. 没有内置函数来执行此操作,因此您需要使用system / exec来执行attrib应用程序。 Like this: 像这样:

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

This will set the hidden (+H) flag on test.txt. 这将在test.txt上设置隐藏(+ H)标志。

You could call attrib : 你可以致电attrib

$filename = 'c:\\some\\file.txt';
exec('attrib +h '.$filename);
// 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. 用'\\'替换'/'很重要,因为shell命令(attrib)不像PHP那样容忍斜杠。
$res is unset first because exec() appends to any existing value. 首先取消设置$ res,因为exec()会附加到任何现有值。

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 如果您正在寻找一种方法将文件设置为只读 ,可以在Windows AND * nix上运行,那么请看看我对这个问题的答案: https//stackoverflow.com/a/27127640/430742

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM