Answers.Body: <p>craft/storage/ is used for all sorts of things, so there’s no single API for storing things in there. Mostly you would just be working with PHP’s standard IO functions like <a href="http://php.net/manual/en/function.file-put-contents.php" rel="nofollow noreferrer">file_put_contents()</a>. There are some handy functions in Craft’s IOHelper class too.</p>
  
  <p>You can get the path to the storage folder via <a href="https://craftcms.com/classreference/services/PathService#getStoragePath-detail" rel="nofollow noreferrer">PathService::getStoragePath()</a>:</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>$storagePath = craft()-&gt;path-&gt;getStoragePath();
  </code></pre>
  
  <p>IOHelper::ensureFolderExists() is a handy function for creating a subfolder for your plugin within craft/storage:</p>
  
  <pre class="lang-php prettyprint-override"><code>$myStoragePath = $storagePath.'myplugin/';
  IOHelper::ensureFolderExists($myStoragePath);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-09T16:25:25.947Z
Answers.Text: It did: https://craftcms.stackexchange.com/questions/1952/is-there-a-way-to-generate-a-url-to-an-image-in-the-craft-storage-myplugin-direc
Answers.UserDisplayName: Ole
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-15T16:36:19.630Z
Answers.Text: Awesome, I kinda figured that may be the case, I just wanted to check before I wrote the code.
Answers.UserDisplayName: Justin Kimbrell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-15T16:48:19.367Z
Answers.Text: One other quick question, is there was way to serve the images that I am saving in storage on the front-end? Is there way to generate a url to that? I am thinking there isn't a way since it's above web root. Anyway you can think of to get around that?
Answers.UserDisplayName: Justin Kimbrell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-15T16:49:10.617Z
Answers.Text: @JustinKimbrell Probably warrants a new question :)
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-15T16:10:29.483Z
Answers.LastActivityDate: 2018-02-21T21:27:17.960Z
Answers.LastEditDate: 2018-02-21T21:27:17.960Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I am building a plugin that needs to cache generated images into a directory in Craft, presumably the <code>craft/storage</code> directory. I took a glance in the docs, but couldn't find much in the form of how to use storage. When building similar functionality in EE I used the their <code>cache</code> directory, so looking for something similar with Craft.</p>
  
  <p>So how does one cache generated files in local directory so they can be used later to prevent the overhead of constantly having to generate the image?</p>
  
Tags: <plugin-development><custom-field>
Title: How does a plugin make use of Craft's storage?
ThreadText: # How does a plugin make use of Craft's storage?
  
  (Asked by: username_0 on 2014-08-15)
  
  I am building a plugin that needs to cache generated images into a directory in Craft, presumably the `craft/storage` directory. I took a glance in the docs, but couldn't find much in the form of how to use storage. When building similar functionality in EE I used the their `cache` directory, so looking for something similar with Craft.
  
  So how does one cache generated files in local directory so they can be used later to prevent the overhead of constantly having to generate the image?
  
  **Tags:** plugin-development, custom-field
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-08-15. Score: 6 | Accepted answer
  
  craft/storage/ is used for all sorts of things, so there’s no single API for storing things in there. Mostly you would just be working with PHP’s standard IO functions like [file\_put\_contents()](http://php.net/manual/en/function.file-put-contents.php). There are some handy functions in Craft’s IOHelper class too.
  
  You can get the path to the storage folder via [PathService::getStoragePath()](https://craftcms.com/classreference/services/PathService#getStoragePath-detail):
  
  ```php
  $storagePath = craft()->path->getStoragePath();
  
  ```
  
  IOHelper::ensureFolderExists() is a handy function for creating a subfolder for your plugin within craft/storage:
  
  ```php
  $myStoragePath = $storagePath.'myplugin/';
  IOHelper::ensureFolderExists($myStoragePath);
  
  ```
  
  > **Comments:**
  > **username_0**: Awesome, I kinda figured that may be the case, I just wanted to check before I wrote the code.  
  > **username_0**: One other quick question, is there was way to serve the images that I am saving in storage on the front-end? Is there way to generate a url to that? I am thinking there isn't a way since it's above web root. Anyway you can think of to get around that?  
  > **username_1**: @username_0 Probably warrants a new question :)  
  > **username_2**: It did: https://craftcms.stackexchange.com/questions/1952/is-there-a-way-to-generate-a-url-to-an-image-in-the-craft-storage-myplugin-direc  
  
  ---
  
  