简体   繁体   中英

Remove a symlink with PHP on Windows

How do I remove a symlink with PHP on windows?

Running this:

mkdir('test');
symlink('test', 'test2');
unlink('test2');

Gives the following error:

PHP Warning:  unlink(test2): Permission denied in C:\path\to\app\testlink.php on line 4
PHP Stack trace:
PHP   1. {main}() C:\path\to\app\testlink.php:0
PHP   2. unlink() C:\path\to\app\testlink.php:4

The directory and symlink were made correctly, just not removed.

Running:

  • PHP 5.4.9 (CLI)
  • Windows 8

Ok, I figured it out. So Ill leave this here for future reference:

To remove a symlink to a directory use the rmdir function:

mkdir('test');
symlink('test', 'test2');
rmdir('test2');

unlink is for removing files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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