Three php file deletion code _ PHP Tutorial

Source: Internet
Author: User
Three types of php file deletion code. Below I have added three php favorites to delete files. he can use unlink to delete any files that can be deleted. this program will delete files, images, and compressed files, we have used several methods to implement the following: I have added three php files to my favorites to delete files. he can use unlink to delete any files that can be deleted. this program will delete files, images, and compressed files, we have used several methods for instance

Below I have added three to my favoritesDelete files in the php TutorialOh, he can useUnlink delete any deletableThis program is used to delete files, images, and compressed files.

Three php file deletion codes

If ($ od = opendir ($ d) // $ d is the directory name.
{
While ($ file = readdir ($ od ))! = False) // www.zhutiai.com
{
Unlink ($ file); // $ file is the file name.
}
}

To solve these three php functions: opendir () readdir () unlink ()

File deletion code 2 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 3

$ Info = "a123"; // directory name
If (is_dir ($ info )){
If (rmdir ($ info )){
Echo "the {$ inof} directory has been deleted. www.bkjia.com ";
} Else {
Echo "directory cannot be deleted! Cause: A file still exists in the directory! ";
}
}
If (is_file ($ info )){
If (unlink ($ info )){
Echo "file {$ info} deleted ...! ";
} Else {
An error occurred while deleting the echo file {$ info} mb.php100.com ...! Try to modify the file permission to delete ...";
If (chmod ($ info, 0777 )){
Unlink ($ info );
Echo "file {$ info} permission modified and deleted ...";
} Else {
Echo "the file {$ info} cannot be deleted on the web. The ftp permission may be set for this file ...";
}
}
}

Recently, many websites have been reposted on this site. please add this site connection. thank you for your cooperation!


...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.