【问题标题】:PHP windows create hidden filesPHP windows创建隐藏文件
【发布时间】:2011-02-08 16:32:34
【问题描述】:

是否可以使用 php (xampp) 在 Windows 上创建隐藏文件/文件夹? 如果是,如何?

【问题讨论】:

  • 在 wWindows 中,您可以隐藏文件,以便默认情况下它们不会对用户可见,仅对操作系统可见。

标签: php windows file hidden


【解决方案1】:

如果 Windows 中的文件设置了 hidden 属性,则该文件将被隐藏。没有内置函数可以执行此操作,因此您需要使用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);
    

    【讨论】:

      【解决方案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
      

      提示:
      将 '/' 替换为 '\' 很重要,因为 shell 命令 (attrib) 对斜杠的容忍度不如 PHP。
      $res 首先未设置,因为 exec() 附加到任何现有值。

      如果您正在寻找一种将文件设置为 只读 且可在 Windows 和 *nix 上运行的方法,请查看我对其他问题的回答:https://stackoverflow.com/a/27127640/430742

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-05
        • 2016-03-09
        • 2011-01-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多