Home > Backend Development > PHP Tutorial > Three PHP file deletion codes_PHP tutorial

Three PHP file deletion codes_PHP tutorial

WBOY
Release: 2016-07-20 11:08:55
Original
965 people have browsed it

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!


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444838.htmlTechArticle Below I have collected three php deletion files. He can use unlink to delete any deletable files. This program requires To delete files, pictures, compressed files, etc., we use several methods to achieve...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template