/** * Creates a new Video model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Video(); if ($model->load(Yii::$app->request->post())) { $model->created_by = Yii::$app->user->id; $model->video_lang = $model->video_lang ? 'AR' : 'EN'; $model->search = $model->video_code . $model->video_url . $model->title_ar . $model->title_en . $model->description_ar . $model->description_en; /*$googleshorter = new GoogleUrlShortener(); $shorturl = $googleshorter->shorten($model->video_url);*/ if ($model->save()) { $tags = Yii::$app->request->post('Video')['tags']; foreach ($tags as &$arr) { $tagvid = new VideoTag(); $tagvid->created_by = Yii::$app->user->id; $tagvid->tag_id = $arr; $tagvid->video_id = $model->id; $tagvid->save(); } } else { return $this->render('create', ['model' => $model]); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $user = auth()->check() ? auth()->user() : null; if (is_null($user)) { return redirect('/')->with('error', 'You need to be logged in'); } if (!$user->can('break_upload_limit') && $user->videos()->newlyups()->count() >= 20) { return redirect()->back()->with('error', 'Uploadlimit reached')->withInput(); } if (!$request->hasFile('file')) { return redirect()->back()->with('error', 'No file')->withInput(); } $file = $request->file('file'); if (!$file->isValid() || $file->getClientOriginalExtension() != 'webm' || $file->getMimeType() != 'video/webm') { return redirect()->back()->with('error', 'Invalid file'); } if (!$user->can('break_max_filesize') && $file->getSize() > 30000000.0) { return redirect()->back()->with('error', 'File to big. Max 30MB')->withInput(); } if (($v = Video::withTrashed()->where('hash', '=', sha1_file($file->getRealPath()))->first()) !== null) { return redirect($v->id)->with('error', 'Video already exists'); } $file = $file->move(public_path() . '/b/', time() . '.webm'); $hash = sha1_file($file->getRealPath()); $video = new Video(); $video->file = basename($file->getRealPath()); $video->interpret = $request->get('interpret', null); $video->songtitle = $request->get('songtitle', null); $video->imgsource = $request->get('imgsource', null); $video->user()->associate($user); $video->category()->associate(Category::findOrFail($request->get('category'))); $video->hash = $hash; $video->save(); return redirect($video->id)->with('success', 'Upload successful'); }
/** * Creates a new Video model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Video(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Video model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Video(); if ($model->load(Yii::$app->request->post())) { $model->url = UrlHelp::translateUrl($model->name); if ($model->validate()) { $model->save(); return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('create', ['model' => $model]); }
/** * Creates a new Video model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Video(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->imageFile = UploadedFile::getInstance($model, 'path'); $path = $model->upload(); if ($path) { $model->path = $path; } $model->save(); return $this->redirect(['view', 'id' => $model->id, 'course_id' => $model->course_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created Video in storage. * * @param CreateVideoRequest $request * * @return Response */ public function store(CreateVideoRequest $request) { $input = $request->all(); $video_url = ''; $thumb_picture_url = ''; if ($request->hasFile('video_url')) { $name = $request->file('video_url')->getClientOriginalName(); $video_url = config('app.url') . ':' . config('app.video_service_port') . '/' . $request->video_url->storeAs('mp4', $name, 'public'); } if ($request->hasFile('thumb_picture_url')) { $name = $request->file('thumb_picture_url')->getClientOriginalName(); $thumb_picture_url = config('app.url') . ':' . config('app.http_service_port') . '/' . $request->thumb_picture_url->storeAs('thumb_pictures', $name, 'public'); } $video = new Video(); $video->title = $input['title']; $video->description = $input['description']; $video->video_url = $video_url; $video->thumb_picture_url = $thumb_picture_url; $video->save(); Flash::success('Video saved successfully.'); return redirect(route('videos.index')); }
public function store(Request $request) { $validation = Validator::make($request->all(), ['titulo' => 'required|string', 'texto' => 'required|string', 'imagens[]' => 'image|mimes:jpeg,bmp,png,jpg']); if ($validation->fails()) { return redirect('admin/videos/novo')->withErrors($validation)->withInput(); } else { try { $video = new Video(); $video->titulo = $request->titulo; $video->texto = $request->texto; $video->data = date('Y-m-d'); $video->save(); if ($request->hasFile('imagens')) { Midia::uploadMultiplo($this->tipo_midia, $video->id_servico); } session()->flash('flash_message', 'Galerias cadastrada com sucesso!'); } catch (\Exception $e) { LogR::exception($video, $e); session()->flash('flash_message', 'Ops!! Ocorreu algum problema!. ' . $e->getMessage()); } return Redirect::back(); } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { if (!$request->hasFile('file') || !$request->has('category') || !$request->has('tags')) { return new JsonResponse(['error' => 'invalid_request']); } $tags = $request->get('tags'); if (mb_strpos($tags, 'sfw') === false && mb_strpos($tags, 'nsfw') === false) { return new JsonResponse(['error' => 'invalid_request']); } $user = auth()->check() ? auth()->user() : null; if (is_null($user)) { return new JsonResponse(['error' => 'not_logged_in']); } if (!$user->can('break_upload_limit') && $user->videos()->newlyups()->count() >= 10) { return new JsonResponse(['error' => 'uploadlimit_reached']); } $file = $request->file('file'); if (!$file->isValid() || mb_strtolower($file->getClientOriginalExtension()) !== 'webm' || mb_strtolower($file->getMimeType()) !== 'video/webm') { return new JsonResponse(['error' => 'invalid_file']); } if (!$user->can('break_max_filesize') && $file->getSize() > 31457280) { return new JsonResponse(['error' => 'file_too_big']); } if (($v = Video::withTrashed()->where('hash', '=', sha1_file($file->getRealPath()))->first()) !== null) { if ($v->trashed()) { return new JsonResponse(['error' => 'already_exists']); } return new JsonResponse(['error' => 'already_exists', 'video_id' => $v->id]); } $file = $file->move(public_path() . '/b/', time() . '.webm'); if (!$this->checkFileEncoding(basename($file->getRealPath()))) { unlink($file->getRealPath()); return new JsonResponse(['error' => 'erroneous_file_encoding']); } $hash = sha1_file($file->getRealPath()); $video = new Video(); $video->file = basename($file->getRealPath()); $video->interpret = $request->get('interpret', null); $video->songtitle = $request->get('songtitle', null); $video->imgsource = $request->get('imgsource', null); $video->user()->associate($user); $video->category()->associate(Category::findOrFail($request->get('category'))); $video->hash = $hash; $video->save(); $video->tag($tags); $video->tag($video->interpret); $video->tag($video->songtitle); $video->tag($video->imgsource); $video->tag($video->category->shortname); $video->tag($video->category->name); $this->createThumbnail(basename($file->getRealPath())); return new JsonResponse(['error' => 'null', 'video_id' => $video->id]); }
/** * addVideo * * Add a new element to DB * * @param $originalName * @param $fileName * @param $newName * @param $userId * @return Video */ public static function addVideo($originalName, $fileName, $newName, $userId) { $result = new Video(); $result->originalName = $originalName; $result->fileName = $fileName; $result->newName = $newName; $result->isConverted = false; $result->createTime = time(); $result->userId = $userId; $result->save(); return $result; }