Reputation: 427
Currently I am using this Imperavi Redactor widget with my Yii Install. https://github.com/yiiext/imperavi-redactor-widget. It currently works but then I noticed I can handle image uploading through the WYSIWYG so I looked on how to enable that which lead me to this:
<?php
$attribute = 'info';
$this->widget('ImperaviRedactorWidget', array(
// The textarea selector
'selector' => '.redactor',
// Options
'options'=>array(
'fileUpload'=>Yii::app()->createUrl('post/fileUpload',array(
'attr'=>$attribute
)),
'fileUploadErrorCallback'=>new CJavaScriptExpression(
'function(obj,json) { alert(json.error); }'
),
'imageUpload'=>Yii::app()->createUrl('post/imageUpload',array(
'attr'=>$attribute
)),
'imageGetJson'=>Yii::app()->createUrl('post/imageList',array(
'attr'=>$attribute
)),
'imageUploadErrorCallback'=>new CJavaScriptExpression(
'function(obj,json) { alert(json.error); }'
),
),
));
?>
but then I dug through redactor.js and noticed that they're S3 functions but currently not sure how to use them as I could not find documentation anywhere about it just standard image uploading. Has anyone ever used this? If so could you lead me in the right direction. Thanks.
Upvotes: 1
Views: 1374
Reputation: 427
Figured it out. Redactor's "S3" directions leave alot to the imagination and just does not seem to work. So I took my own approach.
$this->widget('ImperaviRedactorWidget', array(
// The textarea selector
'selector' => '.redactor',
// Some options, see http://imperavi.com/redactor/docs/
'options'=>array(
'fileUpload'=>'../upload',
'Upload'=>'../upload',
),
));
Created an upload action in the controller.
public function actionUpload(){
$S3_KEY = '';
$S3_SECRET = '';
$S3_BUCKET = '';
$S3_URL = 'http://s3.amazonaws.com/';
// expiration date of query
$tempFile = $_FILES['file']['tmp_name'];
$filename = $_FILES['file']['name'];
$s3 = new A2S3();
$s3->putObject(array(
'Bucket' => $S3_BUCKET,
'Key' => $filename,
'Body' => fopen($tempFile, 'r+'),
'ACL' => 'public-read',
));
$array = array(
'filelink' => 'http://'.$S3_BUCKET.$filename
);
echo stripslashes(json_encode($array));
Upvotes: 1