noumo / easyii

Easy yii2 cms powered by Yii framework 2
http://easyiicms.com
593 stars 272 forks source link

Recipe for getting Redactor 3.0.7 to work with Easyii (file/image upload) #215

Open attybean opened 6 years ago

attybean commented 6 years ago

RedactorController.php: public function actionUpload($dir = '') { // $fileInstance = UploadedFile::getInstanceByName('file'); $fileInstance = UploadedFile::getInstancesByName('file'); if ($fileInstance) { if(is_array($fileInstance)) { $returns = []; foreach ($fileInstance as $key => $file) { if($f = Image::upload($file,$dir)) { $d = $this->getResponse($f); $returns["file-{$key}"] = array_combine(array_merge($d, ['filelink'=> 'url','filename' => 'id']), $d); } } return $returns; } $file = Image::upload($fileInstance, $dir); if($file) { return $this->getResponse($file); } } return ['error' => 'Unable to save image file']; } Changes made to handle multiple file /image upload. Changes made to keys of return object(s)

The return used to look like this: {"filelink":"/uploads/2018/04/85mm-f1-4-ex-dg-hsm-320-84a-9be06c2a4c.jpg","filename":"85mm-f1-4-ex-dg-hsm-320-84a-9be06c2a4c.jpg"} Now it looks like: {"file-0":{"url":"/tmp/images/5723e114ae4775a61c10fe168c18600a.jpg","id":"5723e114ae4775a61c10fe168c18600a"}}