PHP Delete files/folders under the specified directory-How do I delete a file/folder specified under a directory in PHP? _php Tutorials

Source: Internet
Author: User
1

2 $dir = ' directory path you want to delete '; As follows:

3//$dir = $_server[' Document_root '). ' /cache ';

4 Rmdirs ($DIR);

5

6//php Delete files in the specified directory-How do I delete a file specified under a directory in PHP?

7 function Rmdirs ($dir) {

8//error_reporting (0); function returns a state, I use error_reporting (0) to mask out the output

9//rmdir function will return a state, I use @ mask out the output

Ten $dir _arr = Scandir ($dir);

One foreach ($dir _arr as $key + = $val) {

if ($val = = '. ' | | $val = = ' ... ') {}

else {

if (Is_dir ($dir. '/'. $val))

15 {

if (@rmdir ($dir. '/'. $val) = = ' true ') {}//Remove @ You see

+ Else

Rmdirs ($dir. '/'. $val);

19}

Else

Unlink ($dir. '/'. $val);

22}

23}

24}

?>

PHP Delete folders and files under the specified directory-How do I delete a folder and file specified under a directory in PHP?

Author Web Parcel

http://www.bkjia.com/PHPjc/478536.html www.bkjia.com true http://www.bkjia.com/PHPjc/478536.html techarticle 1. php 2 $dir = The directory path you want to delete,//as follows: 3//$dir = $_server[document_root]./cache; 4 rmdirs ($dir); 5 6//php Delete the file under the specified directory-PHP how Delete a directory ...

  • Related Article

    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.