0

My plugin needs to create some directories for its use when it's executed. On many hosts (those using suPHP for example) there is no problem and everything works fine. But on other hosts, PHP does not have permission to write into the plugin's directory, and so all my directory creation attempts fail and the plugin won't work properly.

How can I deal with this? I thought I could temporarily CHMOD the plugin directory, create the things I need, then put it back... but I don't have permission to CHMOD anything either. Do I need to use chown? Or something else...?

Suggestions?

EDIT: I've decided that the most expedient solution is to very carefully document the potential error conditions and provide extremely specific instructions to my users on what to do, should they have permissions issues. It's not the ideal situation I hoped for but hey... waddya gonna do?

4
  • Clearly state this and ask the user that installs the plugin to grant permissions or ask hosting support to do it for him. Also consider storing stuff to the DB. Commented Oct 24, 2011 at 23:10
  • The goal here is specifically to NOT require my users to set any permissions, as experience has shown me asking that of them is a Very Bad Idea. And storing to the DB is an unacceptable option, as this is largely for cache files and I don't want to be adding that kind of load to MySQL. Any other suggestions?
    – JVC
    Commented Oct 24, 2011 at 23:11
  • See if temporary folder is writable... You can't unlock your own prison cell from the inside. You can't CHMOD if you are not allowed to. Commented Oct 24, 2011 at 23:34
  • Yeah the problem with using the "temp" directory is these files aren't always temporary, they might be used for weeks or months. I agree with your analogy, I may just have to throw in the towel on this one and give users very clear instructions on what to set things to if they need to.
    – JVC
    Commented Oct 25, 2011 at 1:03

1 Answer 1

1
  1. First ask yourself if this is really necessary.

  2. Use wp-content/uploads

  3. Use the Filesystem API

4
  • If it wasn't necessary I wouldn't be asking. These are files that are going to be accessed over and over and over again, as they are cache files for on-page elements. Putting them in the uploads directory does not seem to be an appropriate approach, am I wrong? These are files created at page request, so potentially asking the site visitors for FTP info in order to access the required directory, doesn't make sense, and that seems to be how the API would behave, from what I just read.
    – JVC
    Commented Oct 24, 2011 at 23:25
  • @Jonathan - uploads is the most reliably writable folder. you're already aware of the issues outside of this. I would personally use the WP Object Cache and let the user worry about caching with proper caching solutions rather than trying to reinvent wheels.
    – Milo
    Commented Oct 24, 2011 at 23:47
  • You can create a folder in uploads and slap it with a .htaccess and Deny from all. But that folder is used often and the user might come across your files and... decide they should not be there :) Commented Oct 25, 2011 at 1:06
  • Right, exactly one of my concerns. Thanks for the suggestion though!
    – JVC
    Commented Oct 25, 2011 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.