私は、登録ユーザがフロントエンド形式のRedactorリッチテキストフィールドに画像を挿入(アップロード)できるようにします。
ImperaviからImage Managerプラグインをダウンロードしました( https://imperavi.com/redactor/plugins/imagemanager/
)、Redactorの設定を次のように設定します:
{% includeJsResource "lib/redactor/redactor.js" %}
{% includeJsResource "lib/redactor/plugins/source.js" %}
{% includeJsResource "lib/redactor/plugins/fullscreen.js" %}
{% includeJsResource "lib/redactor/plugins/imagemanager.js" %}
{% includeCssResource "lib/redactor/redactor.css" %}
{% set redactorJS %}
$('#{{ elId }}').redactor({
buttons: ['format', 'bold', 'italic', 'deleted', 'lists', 'link', 'html', 'image'],
formatting: ['p', 'blockquote', 'h2', 'h3'],
plugins: ['source','fullscreen', 'imagemanager'],
minHeight: 300,
imageUpload: '/upload.php',
});
{% endset %}
{% includeJs redactorJS %}
イメージボタンをクリックすると、ツールバーのイメージボタンとブラウズファイルのモーダルが表示されます。しかし、
imageUpload: '/upload.php'、
は明らかに間違っているので、何もアップロードしません。
upload.php
を何に置き換えることができますか?これが不可能な場合は、この機能を実現するために他に何ができますか?ありがとう!
UPDATE:
下記のコメントのCloudApp共有リンクの
craft/plugins/imagesuploaderscript/controllers/ImagesUploaderScriptController.php
に次のコードがあります。
namespace Craft;
クラスImagesUploaderScriptControllerはBaseControllerを拡張します {
protected $valid_extensions = array('jpg', 'jpeg', 'png');
protected $assetSourceId = 1;
protected $assetFolderId = 1;
public function actionUpload()
{
$this->requireAjaxRequest();
$errors = array();
$success = array();
if (!$_FILES['file']['error'])
{
$filename = $_FILES['file']['name'];
$file = $_FILES['file']['tmp_name'];
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if (!in_array($extension, $this->valid_extensions))
{
$errors[] = "$filename has an invalid extension.";
} else {
$uploadDir = craft()->assetSources->getSourceById($this->assetSourceId)->settings['path'];
if (move_uploaded_file($file, $uploadDir . $filename))
{
IOHelper::deleteFile($file);
$file = $uploadDir . $filename;
$fileModel = new AssetFileModel();
$fileModel->sourceId = $this->assetSourceId;
$fileModel->folderId = $this->assetFolderId;
$fileModel->filename = IOHelper::getFileName($filename);
$fileModel->kind = IOHelper::getFileKind(IOHelper::getExtension($filename));
$fileModel->size = filesize($file);
$fileModel->dateModified = IOHelper::getLastTimeModified($file);
craft()->assets->storeFile($fileModel);
//print_r($fileModel);
//displaying file
$image = array(
'url' => 'images/'.$filename,
'id' => 1
);
$this->returnJSON($image);
exit;
}
else
{
$errors[] = "$filename was unable to be saved.";
}
}
}
$this->returnJSON(compact('errors'));
exit;
}
}
どのように私のフォームにそれを話すようにするのですか?また、それを稼働させるために他に何をする必要がありますか?
ベストアンサー
ネイティブでは不可能と思われるので、カスタムアップロードスクリプトを書くべきです。
リッチテキストフィールドに画像を追加する必要がない場合は、個別のアップロードフィールドを使用して画像にアップロードすることができます。