Jump to content

$_GET from a URL?


LemonInflux

Recommended Posts

  • Replies 103
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

<?php

$file = $_GET['del'];

$dir = ($f_user);

recursive_delete($dir);

function recursive_delete( $dir )
{
        if (is_dir($dir)) {
           if ($dh = opendir($dir)) {
               while (($file = readdir($dh)) !== false ) {
                        if( $file != "." && $file != ".." )
                        {
                                if( is_dir( $dir . $file ) )
                                {
                                        echo "Entering Directory: $dir$file<br/>";
                                        recursive_delete( $dir . $file . "/" );
                                        echo "Removing Directory: $dir$file<br/><br/>";
                                        rmdir( $dir . $file );
                                }
                                else
                                {
                                        echo "Deleting file: $dir$file<br/>";
                                        unlink( $dir . $file );
                                }
                        }
               }
               closedir($dh);
           }
        }
}

?>

Link to comment
Share on other sites

Oh, yeah, new code:

 

<?php

$file = $_GET['del'];

$dir = ($f_user);

recursive_delete($dir);

function recursive_delete( $dir )
{
        if (is_dir($dir)) {
           if ($dh = opendir($dir)) {
               while (($file = readdir($dh)) !== false ) {
                        if( $file != "." && $file != ".." )
                        {
                                if( is_dir( $dir .'/'. $file ) )
                                {
                                        echo "Entering Directory: $dir / $file<br/>";
                                        recursive_delete( $dir . "/" . $file);
                                }
                                else
                                {
                                        echo "Deleting file: $dir / $file<br/>";
                                        unlink( $dir .'/'. $file );
                                }
                        }
               }
               closedir($dh);
           }
        }
}

?>

Link to comment
Share on other sites

ah screw it try this instead see if it works any better:

<?php
function full_rmdir($dirname)
    {
    if ($dirHandle = opendir($dirname))
        {
        $old_cwd = getcwd();
        chdir($dirname);
        
        while ($file = readdir($dirHandle))
            {
            if ($file == '.' || $file == '..') continue;
            
            if (is_dir($file))
                {
                if (!rmdir_rf($file)) return false;
                }
            else
                {
                if (!unlink($file)) return false;
                }
            }
        
        closedir($dirHandle);
        chdir($old_cwd);
        if (!rmdir($dirname)) return false;
        
        return true;
        }
    else
        {
        return false;
        }
    }
?>

Link to comment
Share on other sites

 <?php $dir = the target directory
$DeleteMe = if true delete also $dir, if false leave it alone

function SureRemoveDir($dir, $DeleteMe) {
    if(!$dh = @opendir($dir)) return;
    while (($obj = readdir($dh))) {
        if($obj=='.' || $obj=='..') continue;
        if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$obj, true);
    }
    if ($DeleteMe){
        closedir($dh);
        @rmdir($dir);
    }
}

//SureRemoveDir('EmptyMe', false);
//SureRemoveDir('RemoveMe', true);

?>

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.