Answers.Body: <p>That's not going to be possible to do without a plugin.</p>
  
  <p>The plugin would need to provide its own <a href="http://buildwithcraft.com/docs/plugins/controllers" rel="nofollow noreferrer">Controller</a> which does the following:</p>
  
  <ol>
  <li>Grab info about the uploaded file using <a href="http://buildwithcraft.com/classreference/etc/web/UploadedFile#getInstanceByName-detail" rel="nofollow noreferrer">UploadedFile::getInstanceByName()</a></li>
  <li>Determine the ID of the asset <em>folder</em> you want to upload the file to using <a href="http://buildwithcraft.com/classreference/services/AssetsService#findFolder-detail" rel="nofollow noreferrer">AssetsService::findFolder()</a></li>
  <li>Move the file into the folder using <a href="http://buildwithcraft.com/classreference/services/AssetsService#insertFileByLocalPath-detail" rel="nofollow noreferrer">AssetsService::insertFileByLocalPath()</a></li>
  </ol>
  
  <p>Here’s an example:</p>
  
  <pre class="lang-php prettyprint-override"><code>// Get info about the uploaded file
  $file = UploadedFile::getInstanceByName('fileInputName');
  $tempFilePath = $file-&gt;getTempName();
  
  // Find the target folder
  $folder = craft()-&gt;assets-&gt;findFolder(array(
      'sourceId' =&gt; 1,
      'path'     =&gt; 'subfolder/path/'
  ));
  
  // Turn the file into a managed asset within that folder
  craft()-&gt;assets-&gt;insertFileByLocalPath(
      $tempFilePath,
      $file-&gt;getName(),
      $folder-&gt;id,
      AssetConflictResolution::KeepBoth);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-11T07:17:02.383Z
Answers.LastActivityDate: 2017-02-20T14:33:32.780Z
Answers.LastEditDate: 2017-02-20T14:33:32.780Z
Answers.UserDisplayName: Andris Sevcenko
Body: <p>I've found information on <a href="http://buildwithcraft.com/docs/assets-fields#uploading-files-from-front-end-entry-forms" rel="nofollow">how to upload an asset as part of creating an entry</a>. What I am trying to do is upload an asset from the frontend <em>without</em> creating an entry. I have a logged in user, and what I would like them to be able to do is upload an asset to a folder that is unique to that user (folder name = username). Help?</p>
  
Tags: <assets><frontend>
Title: How to upload an asset from a front-end form
ThreadText: # How to upload an asset from a front-end form
  
  (Asked by: username_0 on 2014-12-05)
  
  I've found information on [how to upload an asset as part of creating an entry](http://buildwithcraft.com/docs/assets-fields#uploading-files-from-front-end-entry-forms). What I am trying to do is upload an asset from the frontend *without* creating an entry. I have a logged in user, and what I would like them to be able to do is upload an asset to a folder that is unique to that user (folder name = username). Help?
  
  **Tags:** assets, frontend
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-05-11. Score: 9 | Accepted answer
  
  That's not going to be possible to do without a plugin.
  
  The plugin would need to provide its own [Controller](http://buildwithcraft.com/docs/plugins/controllers) which does the following:
  
  1. Grab info about the uploaded file using [UploadedFile::getInstanceByName()](http://buildwithcraft.com/classreference/etc/web/UploadedFile#getInstanceByName-detail)
  2. Determine the ID of the asset *folder* you want to upload the file to using [AssetsService::findFolder()](http://buildwithcraft.com/classreference/services/AssetsService#findFolder-detail)
  3. Move the file into the folder using [AssetsService::insertFileByLocalPath()](http://buildwithcraft.com/classreference/services/AssetsService#insertFileByLocalPath-detail)
  
  Here’s an example:
  
  ```php
  // Get info about the uploaded file
  $file = UploadedFile::getInstanceByName('fileInputName');
  $tempFilePath = $file->getTempName();
  
  // Find the target folder
  $folder = craft()->assets->findFolder(array(
      'sourceId' => 1,
      'path'     => 'subfolder/path/'
  ));
  
  // Turn the file into a managed asset within that folder
  craft()->assets->insertFileByLocalPath(
      $tempFilePath,
      $file->getName(),
      $folder->id,
      AssetConflictResolution::KeepBoth);
  
  ```
  
  
  ---
  
  