I would like to allow users of our site to be able to upload images, mp3's and video from the front-end. Can I do this with the entry form template easily enough?
I was thinking maybe I could use Wistia for the video upload with their widget.
I would like to allow users of our site to be able to upload images, mp3's and video from the front-end. Can I do this with the entry form template easily enough?
I was thinking maybe I could use Wistia for the video upload with their widget.
Yes you can do that with an Entry Form in your template.
Have a look at the assets fields article in the docs, there is a small section about uploading files from front-end forms.
We had the same problem using ckeditor for our WYSIWYG. There was nothing to upload images from the redactor.
So we created a controller action to handle the upload and save the image file into one of our Craft asset source folder.
Here is the complete code, the payload response is adapted to what ckeditor is expecting but you can use the first part for any generic asset upload.
public function actionImageUpload() {
$yourInputName = 'upload';
$yourAssetSrcHandle = 'yourAssetSrcHandle';
$this->requirePostRequest();
$uploadedFile = UploadedFile::getInstanceByName($yourInputName);
$assetSources = craft()->assetSources->getPublicSources('handle');
$assetSource = $assetSources[$yourAssetSrcHandle];
$assetFolder = craft()->assets->getRootFolderBySourceId($assetSource->id);
$response = craft()->assets->insertFileByLocalPath(
$uploadedFile->tempName,
$uploadedFile->name,
$assetFolder->id,
AssetConflictResolution::KeepBoth
);
if ($response->isSuccess())
{
$fileId = $response->getDataItem('fileId');
$file = craft()->assets->getFileById($fileId);
$this->returnJson([
'uploaded' => 1,
'fileName' => $file->filename,
'url' => $file->getUrl(),
'error' => null,
]);
} else {
$this->returnJson([
'uploaded' => 0,
'error' => [
'message' => 'Upload failed'
],
]);
}
}
In case you are using this for a WYSIWYG look at (and update) your HTML purifier config if the image tag is stripped from the field when saving it.
Hope that helps saving someone's time ;) Cheers