Jump to content

Remove Directory With Php Script


Recommended Posts

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.


The part of the original script that created the directory is:


>if ( !is_dir( ABSPATH . 'wp-content/backup-db' ) ) {
  mkdir( ABSPATH . 'wp-content/backup-db' );


and the command I've tried to remove the directory is:




But this returns the error:


>Permission denied in /home/secret_name/public_html/blog/wp-content/New1.php on line 1



So. How can I remove this folder?

Link to comment
Share on other sites

you can always open a help desk ticket to the techs

if you can't get a script to work.



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." :)

Link to comment
Share on other sites

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.



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.



Have you tried it like this?


>exec("rm -r -f /home/secret_name/public_html/blog/wp-content/backup-db");


The rmdir() command worked just fine for me. I'll try this one next time I break something. :)




Thanks, guys!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...