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.
[SOLVED] Deleting directories
Moderator: General Moderators
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
http://uk2.php.net/manual/en/function.rmdir.php
....
when I delete directories I get this error:
This is the code that I have:
These *ARE* valid directories trying to be deleted.
Any help?
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 72Code: 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']."");Any help?