Jump to content

Removing directory and its contents in php


thara

Recommended Posts

I am trying to remove folders and its files and sub folders using php.

This is how I tried it.

    $dir      = "../../images/$category_id/$delId";
    $it      = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
    $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
    foreach($files as $file) {
        if ($file->isDir()){
            rmdir($file->getRealPath());
        } else {
            unlink($file->getRealPath());
        }
    }
    rmdir($dir);

This is working on php 5.5+, but is doesn't work in php 5.2.17.

 

This is the error can I get when it running on php 5.2.17

 

<br /> <b>Fatal error</b>: Undefined class constant 'SKIP_DOTS' in <b>/home2/public_html/admin /includes/process_edit.php</b> on line <b>124</b><br />

 

Can anybody tell me how I get it to work on 5.2 also.
Thank you.

Edited by thara
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.