I have a plugin which needs to create a temporary file. Where should I put it?


PathService has a getTempPath() method which will return the craft/storage/runtime/temp path by default.

Craft uses that for its temporary files and so can plugins. Just make sure youre plugin is being defensive by giving it a unique filename or create a folder with a unique name and put your files in there, etc.

  • Is there a way to directly access files that are placed in the /storage folder? I get file not found if I try to link to it. Sep 25 '15 at 17:48
  • Access from them PHP? Or you want to link to them directly from a template? Probably worth it's own separate post.
    – Brad Bell
    Sep 25 '15 at 22:12
  • Yeah I was trying to link to them from a template, or display it on the template (for pictures). But haven't had any luck. However, now I set up my plugin so files get saved to a location in my plugin resources folder and now able to get the files, so I might just keep this route for now. Sep 26 '15 at 2:06
  • Yeah, that's what I was going to suggest anyway. :)
    – Brad Bell
    Sep 26 '15 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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