I've found information on how to upload an asset as part of creating an entry. 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?
That's not going to be possible to do without a plugin.
The plugin would need to provide its own Controller which does the following:
- Grab info about the uploaded file using UploadedFile::getInstanceByName()
- Determine the ID of the asset folder you want to upload the file to using AssetsService::findFolder()
- Move the file into the folder using AssetsService::insertFileByLocalPath()
Here’s an example:
// 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);