gahhh, directory deleting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

gahhh, directory deleting

Post by s.dot »

I've always had trouble with directory deleting.

Here's the code I used to create the directories:

Code: Select all

$idsql = "SELECT id FROM digitalpics WHERE camsetname = '$dcamsetname'";
$idquery = mysql_query($idsql);
$idarray = mysql_fetch_array($idquery);
mkdir("digital/".$idarrayї'id']."", 0777);
mkdir("digital/".$idarrayї'id']."/thumbs", 0777);
OK, that works fine, both directories ARE created and should have read, write, and execution access.

Here's the code I have to delete both directories:

Code: Select all

function deldir2($dir) {
$dh=opendir("/home/scottttt/public_html/lexylust/digital/$dcamsettodelete/thumbs/");
while ($file=readdir($dh)) {
if($file!="." && $file!="..") {
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)) { unlink($fullpath); } else { deldir($fullpath); } } }
closedir($dh);
if(rmdir($dir)) { return true; } else { return false; }
deldir2("/home/scottttt/public_html/lexylust/digital/$dcamsettodelete/thumbs/");

function deldir($dir) {
$dh=opendir("/home/scottttt/public_html/lexylust/digital/$dcamsettodelete");
while ($file=readdir($dh)) {
if($file!="." && $file!="..") {
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)) { unlink($fullpath); } else { deldir($fullpath); } } }
closedir($dh);
if(rmdir($dir)) { return true; } else { return false; } }
deldir("/home/scottttt/public_html/lexylust/digital/$dcamsettodelete");
It's not deleting. I'm not getting any errors (even checked the error log).
What's wrong?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why is $dh being opened but $dir isn't added to $dh? $dcamsettodelete isn't set anywhere.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

$dcamsettodelete is set from a $_POST['dcamsettodelete'], with register globals being on.

As for the other part, I took this script from PHP.NET, so.. I don't know.
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

you are not decending into your subdirectories, you keep looping through the same directory. You need to call opendir on $dir not a a hard coded folder path.
Post Reply