public function getThumbnails($ref, $event_name) { $uploadFiles = Uploads::find()->where(['ref' => $ref])->all(); $preview = []; foreach ($uploadFiles as $file) { $preview[] = ['url' => self::getUploadUrl(true) . $ref . '/' . $file->real_filename, 'src' => self::getUploadUrl(true) . $ref . '/thumbnail/' . $file->real_filename, 'options' => ['title' => $event_name]]; } return $preview; }
/** * Get a file by ID * * The function returns TRUE or FALSE on failure. If success the file is available in $file param. * @param int $id ID to get * @param object $file Reference to the object * @return bool */ protected function getUpload($id, &$file) { $file = null; $success = false; $request_details = array('conditions' => array('upload_id' => $id)); if ($id > 0) { $success = ($file = Uploads::find('first', $request_details)) ? true : false; } return $success; }
public function actionDeletefileAjax() { $model = Uploads::findOne(Yii::$app->request->post('key')); if ($model !== NULL) { $filename = Album::getUploadPath() . $model->ref . '/' . $model->realfilename; $thumbnail = Album::getUploadPath() . $model->ref . '/thumbnail/' . $model->realfilename; if ($model->delete()) { @unlink($filename); @unlink($thumbnail); echo json_encode(['success' => true]); } else { echo json_encode(['success' => false]); } } else { echo json_encode(['success' => false]); } }
private function getInitialPreview($token_forupload) { $datas = Uploads::find()->where(['ref' => $token_forupload])->all(); $initialPreview = []; $initialPreviewConfig = []; foreach ($datas as $key => $value) { array_push($initialPreview, $this->getTemplatePreview($value)); array_push($initialPreviewConfig, ['caption' => $value->file_name, 'width' => '120px', 'url' => Url::to(['/employee/deletefile']), 'key' => $value->upload_id]); } return [$initialPreview, $initialPreviewConfig]; }
Comments::applyFilter('save', function ($self, $params, $chain) { if ($params['data']) { $params['entity']->set($params['data']); $params['data'] = array(); } if (!$params['entity']->id) { $params['entity']->created = date('Y-m-d H:i:s'); } $params['entity']->updated = date('Y-m-d H:i:s'); return $chain->next($self, $params, $chain); }); Uploads::applyFilter('save', function ($self, $params, $chain) { if ($params['data']) { $params['entity']->set($params['data']); $params['data'] = array(); } if (!$params['entity']->id) { $params['entity']->created = date('Y-m-d H:i:s'); } return $chain->next($self, $params, $chain); }); use lithium\util\Validator; Validator::add('usernameTaken', function ($value) { $success = false; if (strlen($value) != 0) { $success = count(Users::findByUsername($value)) == 0 ? false : true; } return !$success; }); use lithium\core\Libraries; Libraries::add('upload', array('path' => LITHIUM_APP_PATH . '/libraries/_source/upload/')); Libraries::add('captcha', array('path' => LITHIUM_APP_PATH . '/libraries/_source/captcha/', 'webroot' => LITHIUM_APP_PATH . '/libraries/_source/captcha/', "bootstrap" => "securimage.php"));
/** * Deletes an existing Freelance model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $model = $this->findModel($id); //remove upload file & data $this->removeUploadDir($model->ref); Uploads::deleteAll(['ref' => $model->ref]); $model->delete(); return $this->redirect(['index']); }
private function Uploads($isAjax = false) { if (Yii::$app->request->isPost) { $images = UploadedFile::getInstancesByName('picture'); if ($images) { if ($isAjax === true) { $ref = Yii::$app->request->post('ref'); } else { $Comstock = Yii::$app->request->post('Comstock'); $ref = $Comstock['ref']; } $this->CreateDir($ref); foreach ($images as $file) { $fileName = $file->baseName . '.' . $file->extension; $realFileName = md5($file->baseName . time()) . '.' . $file->extension; $savePath = Comstock::UPLOAD_FOLDER . '/' . $ref . '/' . $realFileName; if ($file->saveAs($savePath)) { if ($this->isImage(Url::base(true) . '/' . $savePath)) { $this->createThumbnail($ref, $realFileName); } $model = new Uploads(); $model->ref = $ref; $model->file_name = $fileName; $model->real_filename = $realFileName; $model->save(); if ($isAjax === true) { echo json_encode(['success' => 'true']); } } else { if ($isAjax === true) { echo json_encode(['success' => 'false', 'error' => $file->error]); } } } } } }