Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  EarnestoDev Oct 24 '11 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? –  Jonathan van Clute Oct 24 '11 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. –  EarnestoDev Oct 24 '11 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. –  Jonathan van Clute Oct 25 '11 at 1:03

1 Answer 1

  1. First ask yourself if this is really necessary.

  2. Use wp-content/uploads

  3. Use the Filesystem API

share|improve this answer
    
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. –  Jonathan van Clute Oct 24 '11 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 Oct 24 '11 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 :) –  EarnestoDev Oct 25 '11 at 1:06
    
Right, exactly one of my concerns. Thanks for the suggestion though! –  Jonathan van Clute Oct 25 '11 at 1:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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