Page 1 of 1

gahhh, directory deleting

Posted: Fri Mar 04, 2005 1:35 am
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?

Posted: Fri Mar 04, 2005 7:47 am
by feyd
why is $dh being opened but $dir isn't added to $dh? $dcamsettodelete isn't set anywhere.

Posted: Fri Mar 04, 2005 8:06 am
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.

Posted: Fri Mar 04, 2005 8:31 am
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.