Below I have collected three php files to delete. He can use unlink to delete any deletable files. This program needs to delete files, pictures, compressed files, etc. We have used several methods to demonstrate
Below I have collected three php tutorial to delete filesOh, he can use unlink to delete any deletable files. This program wants to delete files, pictures, compressed files, etc. We have used several methods to illustrate.
Three php deletion file codes
if($od=opendir($d)) //$d is the directory name
{
while(($ file=readdir($od))!==false) //www.zhutiai.com Read the file in the directory
{
unlink($file); //$file is the file name
}
}Learn about these three php functions: opendir() readdir() unlink()
File deletion code two system call method
function del_dir($dir)
{
if(strtoupper(substr(php_os, 0, 3)) == 'win') {
$str = "rmdir /s/q " . $dir;
} else {
$str = "rm -rf " . $dir;
}
}
File deletion code three
$info = "a123"; //Directory name
if(is_dir($info)){
if(rmdir($info)){
echo "Directory {$inof} has been deleted www.bkjia .com";
}else{
echo "The directory cannot be deleted! The reason is that there are still files in the directory!";
}
}
if(is_file($info) ){
if(unlink($info)){
echo "File {$info} has been deleted...!";
}else{
echo "File {$info}mb. php100.com deletion failed...! Try to modify the file permissions to delete...";
if(chmod($info,0777)){
unlink($info);
echo "File{$ The deletion is completed after modifying the info} permissions...";
}else{
echo "The file {$info} cannot be deleted through the web method. It may be that the ftp permissions are set for this file...";
}
}
}
Recently, I found that many websites reprinted the files of this website. Please add the link to this website. Thank you for your cooperation!