簡體   English   中英

PHP窗口創建隱藏文件

[英]PHP windows create hidden files

是否可以使用php(xampp)在Windows上創建隱藏文件/文件夾? 如果是的話,怎么樣?

如果Windows中的文件設置了隱藏屬性,則會隱藏該文件。 沒有內置函數來執行此操作,因此您需要使用system / exec來執行attrib應用程序。 像這樣:

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

這將在test.txt上設置隱藏(+ H)標志。

你可以致電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

提示:
用'\\'替換'/'很重要,因為shell命令(attrib)不像PHP那樣容忍斜杠。
首先取消設置$ res,因為exec()會附加到任何現有值。

如果您正在尋找一種方法將文件設置為只讀 ,可以在Windows AND * nix上運行,那么請看看我對這個問題的答案: https//stackoverflow.com/a/27127640/430742

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM