/** * Return the upload folder path. * * @param type $package * @param type $module * @param type $folder * @param type $field * * @return string */ public function uploadFolder($config, $folder, $field) { $path = config($config . '.upload_folder', config('package.' . $config . '.upload_folder')); if (empty($path)) { throw new FileNotFoundException(); } $folder = folder_decode($folder); return "{$path}/{$folder}/{$field}"; }
/** * @param $url * * @return string */ public function upload($table, $folder, $field, $file = 'file') { if (Request::hasFile($file)) { $dfolder = folder_decode($folder); $array = Filer::upload(Request::file($file), "{$table}/{$dfolder}/{$field}"); $array['efolder'] = "{$table}/{$folder}/{$field}"; Session::push("upload.{$table}.{$field}", $array); return $array; } }
/** * Download the given file. * * @param string $table * @param string $folder * @param string $field * @param string $file * * @return file */ public function file($table, $folder, $field, $file) { $folder = config('files.folder', 'uploads') . '/' . $table . '/' . folder_decode($folder) . '/' . $field; try { $contents = File::get(public_path($folder . '/' . $file)); } catch (FileNotFoundException $exception) { throw new FileNotFoundException(); } $header = ['Content-Type' => 'application/*', 'Cache-Control' => 'max-age=864000, public', 'Expires' => gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 864000), 'Pragma' => 'public']; return Response::make($contents, 200, $header); }
/** * Set upload_folder attribute for the model. * * @param string $value * * @return string */ public function setUploadFolderAttribute($value) { $this->attributes['upload_folder'] = folder_decode($value, false, false); }
/** * Set upload_folder attribute for the model. * * @param string $value * * @return string */ public function setUploadFolderAttribute($value) { $folder['folder'] = folder_decode($value); $folder['encrypted'] = $value; $this->attributes['upload_folder'] = json_encode($folder); }