array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.unlink.php', 1 => 'unlink', ), 'up' => array ( 0 => 'ref.filesystem.php', 1 => '文件系统函数', ), 'prev' => array ( 0 => 'function.umask.php', 1 => 'umask', ), 'next' => array ( 0 => 'book.inotify.php', 1 => 'Inotify', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/filesystem/functions/unlink.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
unlink — 删除文件
删除 filename
。和 Unix C 的
unlink() 函数相似。
发生错误时会产生一个 E_WARNING
级别的错误。
版本 | 说明 |
---|---|
7.3.0 | 现在 Windows 也可以用 unlink() 删除文件句柄还在使用中的文件了,在此之前是无法删除的。 然而,还是无法重新创建文件,需要等到所有句柄都关闭才可以。 |
示例 #1 基本的 unlink() 用法
<?php
$fh = fopen('test.html', 'a');
fwrite($fh, '<h1>Hello world!</h1>');
fclose($fh);
unlink('test.html');
?>