6

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

Marion Newlevant
  • 12,047
  • 22
  • 55

1 Answers1

4

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.

Brad Bell
  • 67,440
  • 6
  • 73
  • 143
  • 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. – Vadim Goncharov 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. – Vadim Goncharov Sep 26 '15 at 02:06
  • Yeah, that's what I was going to suggest anyway. :) – Brad Bell Sep 26 '15 at 17:29