Page 1 of 1

[SOLVED] Deleting directories

Posted: Fri Feb 11, 2005 2:37 am
by s.dot
I have a page where users can delete themselves from my website. I can delete database entries without a problem. However since my website is a picture hog, leaving their pictures on my server is one hell of a waste of space.

I've played around with the unlink() function, but that would involve me doing lots (i mean lots) of queries selecting pictures.

Does anyone know where I can find a script that will delete a given directory's contents, and then delete the folder? This would help me out a bunch. Also, it wouldn't hurt if it chmod 0777 before it deleted, I'm not quite sure of the permissions on these folders, it seems like whenever I set them to 777 they revert to their original permissions after a while.

Posted: Fri Feb 11, 2005 2:51 am
by feyd
we've had several threads recently regarding recursive directory handling.. might want to look at those..

as for your permissions reverting, it's likely a server script that walks the folder tree making sure the permissions are set "correctly"

Posted: Fri Feb 11, 2005 2:52 am
by JayBird
read the user notes int he manual, there is a perfect script there ready made for you

http://uk2.php.net/manual/en/function.rmdir.php

....

Posted: Fri Feb 11, 2005 3:59 pm
by s.dot
when I delete directories I get this error:

Code: Select all

Warning: opendir(/uploads/scrotaye775): failed to open dir: No such file or directory in /home/scottttt/public_html/deleteme.php on line 54

Warning: readdir(): supplied argument is not a valid Directory resource in /home/scottttt/public_html/deleteme.php on line 55

Warning: closedir(): supplied argument is not a valid Directory resource in /home/scottttt/public_html/deleteme.php on line 59

Warning: rmdir(/uploads/scrotaye775): No such file or directory in /home/scottttt/public_html/deleteme.php on line 60

Warning: opendir(/thumbs/scrotaye775): failed to open dir: No such file or directory in /home/scottttt/public_html/deleteme.php on line 66

Warning: readdir(): supplied argument is not a valid Directory resource in /home/scottttt/public_html/deleteme.php on line 67

Warning: closedir(): supplied argument is not a valid Directory resource in /home/scottttt/public_html/deleteme.php on line 71

Warning: rmdir(/thumbs/scrotaye775): No such file or directory in /home/scottttt/public_html/deleteme.php on line 72
This is the code that I have:

Code: Select all

// Delete Uploads Folder //
function deldir($dir) {
$dh=opendir("/uploads/".$_COOKIEї'username']."");
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("/uploads/".$_COOKIEї'username']."");

// Delete thumnails folder //
function deldir2($dir) {
$dh=opendir("/thumbs/".$_COOKIEї'username']."");
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("/thumbs/".$_COOKIEї'username']."");
These *ARE* valid directories trying to be deleted.

Any help?

Posted: Fri Feb 11, 2005 4:02 pm
by feyd
they aren't valid directories.. you are trying to delete root level directories that don't exist, and you don't have access to. You want to delete a directory under your account.. which appears to be under /home/scottttt/public_html/...

...

Posted: Fri Feb 11, 2005 4:27 pm
by s.dot
WOW, thank you! I had no idea it was this simple, I had put this section of my site off for months because I had no idea of how to figure it out. THIS ONE IS SOLVED! :D :D :D :D :D