Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Can't Delete A Folder On Server!, a small mistake in a script....
AnkitGoswami
post Jun 24 2007, 01:40 PM
Post #1


Advanced Member
*******

Group: Members
Posts: 107
Joined: 7-April 07
From: India
Member No.: 41,207



I maintain my college's website and since I update it frequently, I decided to write a php script that would backup all the data in a folder on the server itse
lf. To backup all the data I would only need to run the script once in a while:
CODE

<?
function dircpy($basePath, $source, $dest, $overwrite = false)
{
print "===========================================================================
=
";

if(!is_dir($basePath . $dest))

mkdir($basePath . $dest);

if($handle = opendir($basePath . $source))

{

while(false !== ($file = readdir($handle)))

{

if($file != '.' && $file != '..')

{

$path = $source . '/' . $file;

if(is_file($basePath . $path))

{

print 'File ('.$path.')
';

if(!is_file($basePath . $dest . '/' . $file) || $overwrite)

if(!@copy($basePath . $path, $basePath . $dest . '/' . $file))

{

print 'File ('.$path.') not copied.';

}

}

elseif(is_dir($basePath . $path) && $path!="/backup")

{

print 'Dir ('.$path.')
';

if(!is_dir($basePath . $dest . '/' . $file))

mkdir($basePath . $dest . '/' . $file);

dircpy($basePath, $path, $dest . '/' . $file, $overwrite);

}

}

}

closedir($handle);

}

}

print dircpy("","", "backup/", $overwrite = false);

?>
 

What the script does is copy all the files (including all the files in the subfolders) to the backup folder using recursion. The first time I ran this script I forgot one thing :
elseif(is_dir($basePath . $path) && $path!="/backup")
I did not put the second condition in the above elseif.
Now you might be beginning to understand my problem. The script went into a mad loop and started creating backup/backup/backup/backup/backup/backup....... Now the folders run soo deep that they have exhausted my webspace and I am unable to delete them ('cause of 3 things : first, the folders run too deep, second, they contain .ftpquota files and third, I cannot upload any more files to try and run a script to delete them).

Can anyone think of a solution? 
Go to the top of the page
 
+Quote Post
Saint_Michael
post Jun 24 2007, 01:56 PM
Post #2


$p4m 0n j00 $h4m3 m3 0nc3 $p4m 0n m3 $h4m3 m3 7\/\/1c3
*********************

Group: [HOSTED]
Posts: 6,304
Joined: 21-September 04
From: 9r33|\| 399$ 4|\|D 5P4/\/\
Member No.: 1,218
T17 GFX Crew



First I would chmod the php script so it can't be executed by setting the chmod to 000, then I would download a ftp software and that way you can select all those files for a mass delete. Of course I am assuming that that your back ups under a folder one folder so it should make it rather easy to do, if not just delete the files through a FTP software and you should be set biggrin.gif. Once completed delete your old php script and then upload the one you really need.
Go to the top of the page
 
+Quote Post
Jimmy
post Jun 24 2007, 02:09 PM
Post #3


Super Member
*********

Group: [HOSTED]
Posts: 486
Joined: 9-April 06
From: The UK
Member No.: 21,584



First, i recommend using SM's suggestion of chmodding the script to 000, then:

Well if it's a ftp manager that's refusing to delete them, try using cpanel filemanager and just delete that one folder. Everything should go at once smile.gif
The cpanel will delete it easier since it's on the server, and hence will do it much faster too!

or thirdly, if you want to upload a script to delete them, after chmodding the original script to 000, save a couple of the college's less important files to your computer and then delete them from the server. This should give you enough room to upload a delete script...
BUT be very careful with a delete script. Something may go wrong and clean out your college's webserver, which would cause a lot of annoyances...

This post has been edited by Jimmy: Jun 24 2007, 02:13 PM
Go to the top of the page
 
+Quote Post
AnkitGoswami
post Jun 24 2007, 04:30 PM
Post #4


Advanced Member
*******

Group: Members
Posts: 107
Joined: 7-April 07
From: India
Member No.: 41,207



the trouble is they don't have cpanel but plesk and I hate it. I can't figure out how to use the file manager so I will have to resort to downloading a lot of data and then deleting that on the server to make enough
 room for uploading files.Then I can run a delete script and also change the bac
kup script. The real problem is the site has gone way over the limit (guess the size restriction doesn't apply when you are creating files using php) so I'll have to download a lot and downloading files from ftp is soo slow. 
Go to the top of the page
 
+Quote Post
jlhaslip
post Jun 24 2007, 04:45 PM
Post #5


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,874
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



Is it possible that the php script is being run under a different user than yourself, so you do not have the authority to delete them?
Go to the top of the page
 
+Quote Post
AnkitGoswami
post Jun 24 2007, 06:32 PM
Post #6


Advanced Member
*******

Group: Members
Posts: 107
Joined: 7-April 07
From: India
Member No.: 41,207



well it is not that I can't delete the folder but whenever I try to delete it the ftp client (or explorer) hangs because of the many many folders that were created inside it. It's like backup/backup/backup/backup/backup/backup/backup.....   so the ftp client gets stuck just trying to figure out the time required for deletion.
Go ahead and try the script in localhost without the $path!="/backup" in
elseif(is_dir($basePath . $path) && $path!="/backup")
put the php file in any folder and give the arguments like(in the last line): 
dircpy("","../", "backup/", $overwrite = false);
Go to the top of the page
 
+Quote Post
truefusion
post Jun 24 2007, 07:19 PM
Post #7


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,861
Joined: 22-June 05
From: The World of Gentoo
Member No.: 8,528
T17 GFX Crew



When you create a folder through a script, you lose permission to that folder because it is given the rights to the group "www-data" and not you. The only way to delete that folder is by having a script do it. But the PHP script can only delete folders that are empty.
Go to the top of the page
 
+Quote Post
AnkitGoswami
post Jun 25 2007, 04:41 AM
Post #8


Advanced Member
*******

Group: Members
Posts: 107
Joined: 7-April 07
From: India
Member No.: 41,207



I took care of it last night. Yeah, if you directly use the rmdir function in php it will not be able to remove non 
empty folders so i used unlink for all the files  present and then rmdir (using a modified version of the script above).
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. script hosting?(4)
  2. Move/delete Image On Webpage Automatically?(2)
  3. Script Help! Plz Help(1)
  4. Great Script Site(20)
  5. Html Form Help Please(2)
  6. Several Cms@same Server(5)
  7. Asp Script For A Social Networking Site!(3)
  8. Flash Communications Server(6)
  9. What Is Topsites Script (its In Php)(5)
  10. Free Chat Script(9)
  11. Top Ten Web Script Libraries(6)
  12. How To Incorporate A Php Script To My Website(7)
  13. Log In Script!(6)
  14. Wordpress Databases And Privileges(2)
  15. Reseller Hosting Script(8)