/** * actionCreate * * PUT /resource -> actionCreate -> Create the resource * * @return bool|Video */ public function actionCreate() { try { $uploadedFile = new UploadedFile('data'); if (!$uploadedFile) { throw new ActionCreateException("Error uploading file"); } if (!$uploadedFile->checkAllowedExtension(self::EXTENSION_SOURSE)) { throw new ActionCreateException("File extension is not as expected"); } $fileName = $this->documentPath . uniqid() . self::EXTENSION_SOURSE; $uloadResult = $uploadedFile->upload($fileName); if ($uloadResult !== true) { throw new ActionCreateException($uloadResult); } } catch (ActionCreateException $e) { return $e->getMessage(); } $newName = $this->documentPath . uniqid() . self::EXTENSION_DESTINATION; return Video::addVideo($uploadedFile->originalName, $fileName, $newName, $this->currentUserId()); }
public function show($id) { if ($id) { if ($id == "photos") { $datas = Photo::get(); } elseif ($id == "videos") { $datas = Video::get(); } elseif ($id == "documents") { $datas = Document::get(); } elseif ($id == "audios") { $datas = Audio::get(); } elseif ($id == "uploadedfiles") { $datas = UploadedFile::get(); } return view("Modvel::admin." . $this->theme . ".files.show")->with('datas', $datas)->with('headName', $this->headName); } }
public static function createModule($data) { if (!is_null($data)) { $time = Carbon\Carbon::now()->timestamp; $extension = $data->getClientOriginalExtension(); $mediaName = $time . rand(5, 200000); $fileName = $mediaName . "." . $extension; $data->move(public_path() . '/uploads/modules/', $fileName); $displayName = $mediaName; $uploadedFile = UploadedFile::create(['displayName' => $displayName, 'fileName' => $fileName, 'categoryName' => "UncategorizedModules", 'relId' => 0]); $files = Zipper::make(public_path() . '/uploads/modules/' . $fileName)->listFiles(); $export = Zipper::make(public_path() . '/uploads/modules/' . $fileName)->extractTo(app_path() . '/Modules'); $detailsFile = ""; foreach ($files as $file) { //details.php $detailsphp = substr($file, -11); if ($detailsphp == "details.php") { $detailsFile = $file; } } if ($detailsFile == "") { return redirect('/'); } $path = (include app_path() . '/Modules/' . $detailsFile); return $path; } }
/** * @return \yii\db\ActiveQuery */ public function getFile() { return $this->hasOne(UploadedFile::className(), ['id' => 'file_id']); }