to delete all the files in a directory
<?php
foreach (glob("directorypath/*.*") as $filename)
{
unlink($filename);
}
?>
unlink说明bool unlink ( string filename )删除 filename。和 Unix C 的 unlink() 函数相似。如果成功则返回 TRUE,失败则返回 FALSE。
参见目录删除函数 rmdir()。
tristan
17-Oct-2006 12:01
to delete all the files in a directory
paul at pes-systems dot net
17-Aug-2006 01:27
A work around for the Permission Denied problem.
khalidz83 at yahoo dot co dot uk
15-Feb-2006 11:18
If you get an error while deleting a file from the system, check who is the owner of the file. For example if you move to another system and the owner is 'nobody' then the owner should be nobody for that file on the new system.If you delete as another user, you will get an error.
Anarcho at ssm-clan dot de
27-Nov-2005 06:56
Just to be a bit more accurate to the post of "jchase at solidmark dot com":
bishop
06-Jun-2005 03:30
<?php
jchase at solidmark dot com
21-May-2005 01:05
[Editor's note: A suggestion for a work-around was submitted by argistof at gmail dot com: You can use the recursive option (see man chmod) when chmodding, for instance 'chmod 777 directory/ -R'. Be aware though, this will change the permissions of all files and folders in the diectory.]
kickthedonkey at gmail dot com
17-May-2005 07:24
Regarding the comment by 'admin at crazydrumguy dot info': You might want to consider using is_file instead of file_exists if you're wanting to target a file specifically (and not a directory). file_exists($name) will return true if $name contains a path to a directory (which may or may not be what you want to do...)
ashley at semantic dot org
02-Apr-2005 06:50
Actually you should use "@unlink" rather than testing with file_exists. The former is atomic, whereas the latter can break if you can't guarantee only one process will try to delete a given file at a time.
dagski_AT_gmail_DOT_com
07-Feb-2005 02:19
before you could unlink a file created which uses a handle e.g.,
chris at vibenewmedia dot com
15-Sep-2004 01:54
To delete all files of a particular extension, or infact, delete all with wildcard, a much simplar way is to use the glob function. Say I wanted to delete all jpgs .........
pc AT newagelab DOT com DOT ua
08-Sep-2004 11:22
To delete files using wildcards:
| ||