public function saveVideo() { $title1 = 'Video'; $title = 'Saved'; $v = new Videos(); $v->video_url = \Input::get('video_url'); $v->video_author = \Input::get('video_author'); $v->video_name = \Input::get('video_name'); $v->video_artist = \Input::get('video_artist'); $v->video_album = \Input::get('video_album'); $v->video_description = \Input::get('video_description'); $v->user()->associate(\Auth::user()); // belongsTo $v->save(); return view('video_saved')->with('title1', $title1)->with('title', $title); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { // if (Request::hasFile('video')) { $videoFile = Request::file('video'); $fileExt = $videoFile->getExtension(); $ext = strtolower($videoFile->getClientOriginalExtension()); switch ($ext) { case "mov": case "m4v": case "mp4": case "wmv": case "avi": $video = new Videos(); $video->videoFile = VideosController::saveFileToS3($videoFile); $video->videoThumbnail = VideosController::createThumbnail($videoFile); $video->title = $request::input('title'); $video->studentName = $request::input('studentName'); $video->className = $request::input('className'); $video->houseName = $request::input('houseName'); $video->videoDescription = $request::input('videoDescription'); $video->save(); // Large files may be rejected if apache config is configured with a low limit: // upload_max_filesize = 4096; // post_max_size = 4096; VideosController::slack($video->studentName . ' from ' . $video->className . ' has successfully uploaded a video called ' . $video->title . '. http://www.stbons.co.uk/video/show/' . $video->id . '/', 'StBons.co.uk', 'movie_camera'); return Redirect::to('video/show/' . $video->id)->with('message', 'Thank you for your video!'); break; default: return Redirect::to('video/upload/')->with('error', 'The file type "' . $videoFile->getClientOriginalExtension() . '" is not allowed'); break; } } else { return Redirect::to('video/upload/')->with('error', 'Please choose a video to upload'); } }
public function postUpload(Request $request) { if (!empty($request->file('photo')) or !empty($request->url)) { if (5 < count($request->file('photo'))) { $message = "Você enviou mais fotos do que o permitido!"; return redirect(url('/'))->with(compact('message')); } else { $userId = Auth::user()->id; $quantityPhotos = Photos::quantityPhotosByUser($userId); $quantityVideos = Videos::quantityVideosByUser($userId); $quantityPhotosAvailable = 5 - $quantityPhotos; if ($quantityPhotosAvailable < count($request->file('photo'))) { $message = "Você enviou mais fotos/vídeo do que o permitido!"; return redirect(url('/'))->with(compact('message')); } else { $folder = 'assets/images/_upload/fotos/' . $userId . '/'; if (!File::exists($folder)) { File::makeDirectory($folder, 0777); } if (!empty($request->url) and (substr_count($request->url, "http://") == 1 or substr_count($request->url, "https://") == 1) and $quantityVideos == 0) { $videoAdd = new Videos(); $videoAdd->usersId = $userId; $videoAdd->url = $request->url; $videoAdd->save(); } if (!empty($request->file('photo'))) { foreach ($request->photo as $file) { if (!is_null($file)) { if ($file->getSize() > 2048000 or $file->getSize() == 0) { $message = "As fotos não podem ser maiores que 2Mb!"; return redirect(url('/'))->with(compact('message')); } else { $photoAdd = new Photos(); $photoAdd->usersId = $userId; //IMAGE $extension = $file->getClientOriginalExtension(); $nameImage = Carbon::now()->format('YmdHis') . "_" . rand(0, 999999) . "." . $extension; Image::make($file)->resize(800, null, function ($constraint) { $constraint->aspectRatio(); })->save($folder . $nameImage); Image::make($file)->resize(null, 231, function ($constraint) { $constraint->aspectRatio(); })->save($folder . "thumb_" . $nameImage); $photoAdd->photo = $nameImage; $photoAdd->save(); } } else { if (is_null($file) and empty($request->url)) { $message = "Envie pelo menos uma foto ou vídeo!"; return redirect(url('/'))->with(compact('message')); } } } } $message = "Mídias enviadas com sucesso!"; return redirect(url('/'))->with(compact('message')); } } } else { $message = "Envie pelo menos uma foto ou vídeo!"; return redirect(url('/'))->with(compact('message')); } }