PHP windows create hidden files

前端 未结 3 947
孤独总比滥情好
孤独总比滥情好 2021-01-06 09:16

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

3条回答
  •  春和景丽
    2021-01-06 10:01

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

提交回复
热议问题