Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod computer crash drive driver drivers error ethernet excel freeze games gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard netgear network printer problem ram random registry router slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: how to delete and directory and its contents with PHP

Reply  
Thread Tools
emopoops's Avatar
emopoops has a Photo Album
Computer Specs
Member with 195 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
23-Oct-2009, 05:22 PM #1
Question Solved: how to delete and directory and its contents with PHP
HOW DO U DO IT? i need to know the php coding
cwwozniak's Avatar
Computer Specs
Trusted Advisor with 32,989 posts.
 
Join Date: Nov 2005
Location: McHenry, IL - USA
Experience: Enough to be dangerous
23-Oct-2009, 05:55 PM #2
I believe you first need to individually delete each file in the directory and then delete the empty directory.

The unlink( ) function deletes a specific file.
http://www.w3schools.com/php/func_filesystem_unlink.asp

The rmdir( ) function deletes a specific empty directory
http://www.w3schools.com/PHP/func_filesystem_rmdir.asp

You can use the scandir( ) function to build an array containing the file names in a directory.
http://www.w3schools.com/php/func_directory_scandir.asp
__________________
Chuck W.
I am not in this world to live up to your expectations, And you are not in this world to live up to mine. - Fritz Perls
emopoops's Avatar
emopoops has a Photo Album
Computer Specs
Member with 195 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
24-Oct-2009, 09:23 AM #3
why isnt this working for me? i want to delete the directory and the contents:
Code:
<?php 
$documentroot = $_SERVER['DOCUMENT_ROOT'];

$username = "Administrator";
$dir = $documentroot . '/' . $username;
function rmdir_r ( $dir, $DeleteMe = TRUE )
{
    if ( ! $dh = @opendir ( $dir ) ) return;
    while ( false !== ( $obj = readdir ( $dh ) ) )
    {
        if ( $obj == '.' || $obj == '..') continue;
        if ( ! @unlink ( $dir . '/' . $obj ) ) rmdir_r ( $dir . '/' . $obj, true );
    }
    
    closedir ( $dh );
    if ( $DeleteMe )
    {
        @rmdir ( $dir );
    }
}
?>
cwwozniak's Avatar
Computer Specs
Trusted Advisor with 32,989 posts.
 
Join Date: Nov 2005
Location: McHenry, IL - USA
Experience: Enough to be dangerous
24-Oct-2009, 12:21 PM #4
I am still a rank beginner as far as writing and debugging PHP is concerned. It may take me some time to go through your function. Anyone else here is more than welcome to jump in and help out.
emopoops's Avatar
emopoops has a Photo Album
Computer Specs
Member with 195 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
24-Oct-2009, 12:32 PM #5
lol yeah simple thing i couldnt figure out. someone had to tell me i have to call the function! lol cause it wasnt being called so i had to add
rmdir_r($dir); at the bottom(not in the function) i thot it was huge time concerning thing too! until someone pointed out the "obvious" i guess i just get put off by big lines of code LOL. thanks for replying
cwwozniak's Avatar
Computer Specs
Trusted Advisor with 32,989 posts.
 
Join Date: Nov 2005
Location: McHenry, IL - USA
Experience: Enough to be dangerous
24-Oct-2009, 06:46 PM #6
Glad to hear you figured it out. I probably would not have thought of that little detail myself.
emopoops's Avatar
emopoops has a Photo Album
Computer Specs
Member with 195 posts.
 
Join Date: Jan 2009
Location: america c- ountry
Experience: pretty experinced ;]
25-Oct-2009, 06:41 PM #7
thanks
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 04:33 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.