public static function store($files, $material) { // Making counting of uploaded images $file_count = count($files); // start count how many uploaded $uploadcount = 0; if (!empty($files)) { foreach ($files as $file_path) { if (!empty($file_path)) { $type = File::type($file_path); $mime = File::mimeType($file_path); $extension = File::extension($file_path); $filename = $material->slug . '_' . str_replace(' ', '_', File::name($file_path)) . '.' . $extension; File::move($file_path, storage_path() . '/app/' . $filename); //add file path and thumb path to material_files database $material_file = MaterialFile::firstOrCreate(['original_filename' => File::name($file_path), 'filename' => $filename, 'mime' => $mime]); //add to material file table $material->files()->save($material_file); $uploadcount++; //create thumb MaterialFile::makeThumb($extension, $filename); } } if ($uploadcount == $file_count) { Session::flash('success', 'Upload(s) successfully'); } else { return Redirect::to('material.edit')->withInput(); } } }
public function view($image) { $path = storage_path() . '/uploads/' . $image; if (File::exists($path)) { $filetype = File::type($path); $response = Response::make(File::get($path), 200); $response->header('Content-Type', $filetype); return $response; } return false; }
/** * Big Upload * ini adalah upload menggunakan metode chuck * dengan ajax file */ public function bigUploads() { $bigUpload = new BigUpload(); $folder = $this->uploadfile->getUploadFolder(); $bigUpload->setTempDirectory(public_path('/videos/tmp')); $bigUpload->setMainDirectory($folder); $bigUpload->setTempName(Input::get('key', null)); switch (Input::get('action')) { case 'upload': return $bigUpload->uploadFile(); break; case 'abort': return $bigUpload->abortUpload(); break; case 'finish': $rand = Str::random(10); $randomname = $rand . '.' . Input::get('ext'); $finish = $bigUpload->finishUpload($randomname); if (0 === $finish['errorStatus']) { // Create a new order if not exist if (null === $this->model) { $this->model = $this->repository->getModel()->newInstance(); /* //shell_exec("ffmpegthumbnailer -i " . $folder. $randomname ." -o ". static::$app['path.base']."/public/covers/" . $rand . ".png -s 400"); shell_exec("ffmpeg -itsoffset -5 -i ". $folder. $randomname ." -vcodec mjpeg -vframes 5 -an -f rawvideo ".static::$app['path.base']."/public/covers/" . $rand . ".jpg"); //Sonus::convert()->input( $folder. $randomname )->output(static::$app['path.base'].'/public/streams/' . $randomname )->go(); $resolusi = $this->__get_video_dimensions($folder.$randomname); if($resolusi['height'] >= 720){ shell_exec("ffmpeg -i {$folder}{$randomname} -s 960x720 -vcodec h264 -acodec aac -strict -2 {$folder}{$rand}_720.mp4"); } shell_exec("ffmpeg -i {$folder}{$randomname} -s 480×360 -vcodec h264 -acodec aac -strict -2 {$folder}{$rand}_360.mp4"); */ // File extension $this->model->code = $rand; $this->model->extension = File::extension($folder . $randomname); $this->model->mimetype = File::type($folder . $randomname); $this->model->owner_id = $this->ownerId; $this->model->size = File::size($folder . $randomname); $this->model->path = $this->uploadfile->cleanPath(static::$app['config']->get('video.upload_folder_public_path')) . $this->uploadfile->dateFolderPath; $this->model->filename = $randomname; $this->model->playback = $randomname; $this->model->cover = $rand . '.png'; $this->model->save(); if (null !== $this->model) { $info = $this->infoRepository->getModel()->where('video_id', $this->model->getId())->first(); // Create a new item $info = $info ? $info : $this->infoRepository->getModel()->newInstance(); $info->fill(array_merge(array('name' => Input::get('name')), array('video_id' => $this->model->getId()))); if (!$info->save()) { throw new Exception("Could not create a video info"); } } } return array('errorStatus' => 0, 'id' => $this->model->getId(), 'code' => $this->model->code); } return $finish; break; case 'post-unsupported': //return $bigUpload->postUnsupported(); return $this->upload(Input::file('bigUploadFile')); break; } }