Remove Directory With Php Script

liunx

Guest
I allowed a PHP script (plugin for WordPress) to create a directory. Now the directory is owned by a different user ID. I can't read from it, write to it or change permissions. I've tried using a simple PHP script to remove the directory (thinking if PHP created it, PHP can remove it), but that doesn't work.<br /><br />The part of the original script that created the directory is:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->if ( !is_dir( ABSPATH . 'wp-content/backup-db' ) ) {<br />   mkdir( ABSPATH . 'wp-content/backup-db' );<br />}<!--c2--></div><!--ec2--><br /><br />and the command I've tried to remove the directory is:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->rmdir('/home/secret_name/public_html/blog/wp-content/backup-db');<!--c2--></div><!--ec2--><br /><br />But this returns the error:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Permission denied in /home/secret_name/public_html/blog/wp-content/New1.php on line 1<!--c2--></div><!--ec2--><br /><br /><br />So. How can I remove this folder?<!--content-->
you can always open a help desk ticket to the techs<br />if you can't get a script to work.<!--content-->
<!--quoteo(post=203437:date=Mar 30 2007, 11:11 PM:name=TCH-Don)--><div class='quotetop'>QUOTE(TCH-Don @ Mar 30 2007, 11:11 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=203437"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->you can always open a help desk ticket to the techs<br />if you can't get a script to work.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br /><br />Understood, but if it's possible to resolve this myself, I'd like to. This issue pops up now and again among my TCH-using friends and I'd like to be able to offer a better solution than simply "the help desk can fix it." <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /><!--content-->
I just did a quick check in PHP, and you can remove the folder that way as long as you have permissions on that directory and it's parent directory.<!--content-->
Have you tried it like this?<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->exec("rm -r -f /home/secret_name/public_html/blog/wp-content/backup-db");<!--c2--></div><!--ec2--><!--content-->
<!--quoteo(post=203442:date=Mar 31 2007, 03:48 AM:name=TCH-Andy)--><div class='quotetop'>QUOTE(TCH-Andy @ Mar 31 2007, 03:48 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=203442"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->I just did a quick check in PHP, and you can remove the folder that way as long as you have permissions on that directory and it's parent directory.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br /><br />Oh, duh. I forgot to give appropriate permissions to the parent directory. Yeah, my first idea does work, so long as I give the parent of the folder to be removed temporarily higher permissions.<br /><br /><br /><!--quoteo(post=203455:date=Mar 31 2007, 09:17 AM:name=TCH-Bruce)--><div class='quotetop'>QUOTE(TCH-Bruce @ Mar 31 2007, 09:17 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=203455"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->Have you tried it like this?<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->exec("rm -r -f /home/secret_name/public_html/blog/wp-content/backup-db");<!--c2--></div><!--ec2--><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />The rmdir() command worked just fine for me. I'll try this one next time I break something. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /><br /><br /><br /><br />Thanks, guys!<!--content-->
Glad you got it working. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->
 
Top