/** * Delete the directory with the filename and all files inside * Fire FileWasDeleted Event * */ public function handle() { if (Storage::exists($this->getFileDirectory())) { Storage::deleteDirectory($this->getFileDirectory()); } event(new FileWasDeleted($this->filename)); }
/** * Store a newly created resource in storage. * * @return Response * @throws ImageFailedException * @throws \BB\Exceptions\FormValidationException */ public function store() { $data = \Request::only(['user_id', 'category', 'description', 'amount', 'expense_date', 'file']); $this->expenseValidator->validate($data); if (\Input::file('file')) { try { $filePath = \Input::file('file')->getRealPath(); $ext = \Input::file('file')->guessClientExtension(); $mimeType = \Input::file('file')->getMimeType(); $newFilename = \App::environment() . '/expenses/' . str_random() . '.' . $ext; Storage::put($newFilename, file_get_contents($filePath), 'public'); $data['file'] = $newFilename; } catch (\Exception $e) { \Log::error($e); throw new ImageFailedException($e->getMessage()); } } //Reformat from d/m/y to YYYY-MM-DD $data['expense_date'] = Carbon::createFromFormat('j/n/y', $data['expense_date']); if ($data['user_id'] != \Auth::user()->id) { throw new \BB\Exceptions\FormValidationException('You can only submit expenses for yourself', new \Illuminate\Support\MessageBag(['general' => 'You can only submit expenses for yourself'])); } $expense = $this->expenseRepository->create($data); event(new NewExpenseSubmitted($expense)); return \Response::json($expense, 201); }
public function actualizar($id, Request $request) { try { $rules = array('nombre' => array('required', 'string', 'min:5', 'unique:promociones,nombre' . $id), 'descripcion' => array('required', 'string', 'min:30'), 'imagen' => array('image', 'image_size:>=300,>=300'), 'inicio' => array('date'), 'fin' => array('date', 'after: inicio')); $this->validate($request, $rules); $registro = Promociones::find($id); $registro->nombre = \Input::get('nombre'); $registro->descripcion = \Input::get('descripcion'); if ($archivo = BRequest::file('foto')) { $foto = BRequest::file('imagen'); $extension = $foto->getClientOriginalExtension(); Storage::disk('image')->put($foto->getFilename() . '.' . $extension, File::get($foto)); $registro->imagen = $foto->getFilename() . '.' . $extension; } if ($inicio = \Input::get('inicio')) { $registro->inicio = \Input::get('inicio'); } if ($inicio = \Input::get('fin')) { $registro->fin = \Input::get('fin'); } $registro->save(); return \Redirect::route('adminPromociones')->with('alerta', 'La promocion ha sido modificada con exito!'); } catch (ValidationException $e) { return \Redirect::action('PromocionesCtrl@editar', array('id' => $id))->withInput()->withErrors($e->get_errors()); } }
public function add(Request $request) { $name = Input::get('user_name'); $id = Input::get('user_id'); $text = Input::get('description'); if ($request->hasFile('filefield')) { $file = $request->file('filefield'); $entry = new Fileentry(); $filename = time() . '.' . $file->getClientOriginalExtension(); $extension = $file->getClientOriginalExtension(); // Image::make($file)->orientate()->save(public_path('recipe/'. $filename)); Storage::disk('local')->put($file->getFileName() . '.' . $extension, File::get($file)); $entry->mime = $file->getClientMimeType(); $entry->original_filename = $file->getClientOriginalName(); $entry->filename = $file->getFilename() . '.' . $extension; } $entry->user_name = $name; $entry->user_id = $id; $entry->description = $text; $entry->save(); // $file = Request::file('filefield'); // $extension = $file->getClientOriginalExtension(); // Storage::disk('local')->put($file->getFilename().'.'.$extension, File::get($file)); // $entry = new Fileentry(); // $entry->mime = $file->getClientMimeType(); // $entry->original_filename = $file->getClientOriginalName(); // $entry->filename = $file->getFilename().'.'.$extension; // $entry->user_name = $name; // $entry->user_id = $id; // $entry->description = $text; // // $entry->save(); return redirect('/'); }
/** * Bootstrap the application services. * * @return void */ public function boot() { Storage::extend('bos', function ($app, $config) { $client = new BosClient($config); return new Filesystem(new BosAdapter($client, $config)); }); }
public function add() { $file = Request::file('file'); if (Request::hasFile('file')) { $extension = $file->getClientOriginalExtension(); Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file)); $entry = new \App\File(); $entry->mime = $file->getClientMimeType(); $entry->original_filename = $file->getClientOriginalName(); $entry->filename = $file->getFilename() . '.' . $extension; $entry->save(); $part = new Part(); $part->file_id = $entry->id; $part->name = Request::input('name'); $part->sku = Request::input('sku'); $part->make = Request::input('make'); $part->year = Request::input('year'); $part->condition = Request::input('condition'); $part->description = Request::input('description'); $part->price = Request::input('price'); $part->imageurl = Request::input('imageurl'); if (Request::has('price')) { $part->save(); } } return redirect('/admin/part'); }
protected function downloadFileInWindowsNT(TFFile $file) { $client = new Client(); try { $response = $client->get($file->source, ['verify' => false]); } catch (\Exception $e) { $error = 'TFDownloader: Downloading file failed, url is %s, msg is %s.'; $error = sprintf($error, $file->source, $e->getMessage()); Log::error($error); $file->state = 'error'; $file->error = $error; $file->save(); return; } if ($response->getStatusCode() == 200) { $location = 'file/' . $file->name; Storage::put($location, $response->getBody()); $file->state = 'downloaded'; $file->location = $location; $file->save(); return; } else { $error = 'TFDownloader: Bad HTTP response code in downloading videos, url is %s, status code is %d.'; $error = sprintf($error, $file->source, $response->getStatusCode()); Log::error($error); $file->state = 'error'; $file->error = $error; $file->save(); return; } }
public function resize($image) { $width = config('medias.max_size.width'); $height = config('medias.max_size.height'); // this orientate method needs to be called because sometimes // images uploaded came rotated, but need to be ajusted $img = $this->image->make(Storage::disk(config('medias.disk'))->get($image))->orientate(); if ($img->width() <= $width && $img->height() <= $height) { return; } if ($img->width() > $width && $img->height() > $height) { $img->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); Storage::disk(config('medias.disk'))->put($image, $img->stream()); return; } if ($img->width() > $width) { $height = null; } elseif ($img->height() > $height) { $width = null; } $img->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); Storage::disk(config('medias.disk'))->put($image, $img->stream()); }
function upload_file($file) { $extension = $file->getClientOriginalExtension(); $filename = $file->getFilename() . '.' . $extension; Storage::disk('local')->put($filename, File::get($file)); return $filename; }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $validator = Validator::make($request->all(), ['customer_id' => 'required|numeric', 'location' => 'required|max:100', 'name' => 'required|max:100', 'description' => 'required|max:150', 'content' => 'required|in:complete,modify', 'type' => 'required|in:file,url']); if ($validator->fails()) { return redirect('admin/feeds/create')->withInput()->withErrors($validator); } if ($request->hasFile('feed')) { // $file = $request->file('feed'); $extension = $file->getClientOriginalExtension(); Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file)); //return Redirect::to('admin/users/create') //->withInput() //->withErrors(array('message' => 'Login field is required.')); //http://stackoverflow.com/questions/18367769/how-to-use-witherrors-with-exception-error-messages-in-laravel4 } //$input = $request->all(); //Feed::create($input); $feed = new Feed(); $feed->customer_id = $request->customer_id; $feed->name = $request->name; $feed->location = $request->location; $feed->type = $request->type; $feed->content = $request->content; $feed->description = $request->description; $feed->save(); //$feed = new Feed(Input::all())->save(); Activity::log(Auth::user()->name . ' Add feed:' . $request->name); //Activity::log(Auth::user()->name.' Add file:'.$file->name); return redirect('admin/feeds'); }
/** * Execute the job. * * @return void */ public function handle() { // get directory path from file $goalDirectory = pathinfo($this->path, PATHINFO_DIRNAME); // get all subdirectories $directories = Storage::disk('powerimage')->allDirectories($goalDirectory); // delete resized iamges foreach ($directories as $directory) { if ($goalDirectory == '.') { // root directory $checkPath = $directory . '/' . $this->path; } else { // subdirectory $checkPath = str_replace($goalDirectory, $directory, $this->path); } if (Storage::disk('powerimage')->exists($checkPath)) { Storage::disk('powerimage')->delete($checkPath); } } // delete original image if (Storage::disk('powerimage')->exists($this->path)) { Storage::disk('powerimage')->delete($this->path); return true; } return false; }
/** * Rename the file directory to rename the file in the system * */ public function handle() { if (Storage::exists($this->getOldFileDirectory())) { Storage::move($this->getOldFileDirectory(), $this->getNewFileDirectory()); } event(new FileWasRenamed($this->from, $this->to)); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $file = Request::file('xmlfile'); $type = Input::get('type'); $userid = Input::get('userid'); $alpha = Input::get('alpha'); $extension = $file->getClientOriginalExtension(); $oname = $file->getClientOriginalName(); Storage::disk('local')->put("uploads/" . $file->getClientOriginalName(), File::get($file)); $parser = new Parser(); $contents = Storage::get("uploads/" . $file->getClientOriginalName()); $rawxml = $parser->xml($contents); $importer = new Importer(); if ($type == 'recipes') { $importer->parseRecipe($rawxml, $userid, $alpha, 1); } if ($type == 'blocks') { $importer->parseBlocks($rawxml, $userid, $alpha, 1); } if ($type == 'materials') { $importer->parseMaterial($rawxml, $userid, $alpha, 1); } if ($type == 'items') { $importer->parseItems($rawxml, $userid, $alpha, 1); } //Flash::success('You successfully imported a '.$type.' xml file for 7 Days to Die Alpha '.$alpha.'!'); return view('pages.import'); }
public function upload() { $path = $this->folder . '/' . $this->newFileName; $content = file_get_contents($this->file->getRealPath()); Storage::put($path, $content); return 'uploads/' . $path; }
public function get($filename) { $entry = Fileentry::where('filename', '=', $filename)->firstOrFail(); $file = Storage::disk('local')->get($entry->filename); //dd(Response($file, 200)->header('Content-Type', $entry->mine)); return Response($file, 200)->header('Content-Type', $entry->mine); }
public static function getLatest() { return self::remember('latest', function () { $meta = json_decode(Storage::disk('local')->get('subtitles/meta.json'), true); return $meta['latest']; }); }
public function administraFotoPerfil($model, $file) { if (!is_null($file) or !empty($file)) { if ($model->foto != '' and Storage::disk('assets')->has('perfil/' . $model->foto)) { Storage::disk('assets')->delete('perfil/' . $model->foto); } if ($model->avatar != '' and Storage::disk('assets')->has('perfil/' . $model->avatar)) { Storage::disk('assets')->delete('perfil/' . $model->avatar); } $extArquivo = $file->getClientOriginalExtension(); $nomeArquivo = 'CP.' . $model->company_id . '.ID.' . $model->id . '.T.' . Carbon::now()->timestamp . '.' . $extArquivo; $model->foto = $nomeArquivo; $model->avatar = 'AVT.' . $nomeArquivo; $model->save(); $img = Image::make($file); $img->orientate(); $img->resize(400, null, function ($constraint) { $constraint->aspectRatio(); }); $img->crop(250, 250); $img->save(storage_path('app/assets/perfil/' . $nomeArquivo)); $img->resize(60, null, function ($constraint) { $constraint->aspectRatio(); }); $img->save(storage_path('app/assets/perfil/' . $model->avatar)); } return true; }
public function handle() { switch ($this->argument('option')) { case 'slotitem': $this->info('Fetching lua table in kcwiki.moe...'); $data = json_decode(file_get_contents($this->slotitem_url), true); $content = $data['query']['pages'][5462]['revisions'][0]['*']; $re = "/p.equipDataTb = \\{.*\\}/s"; preg_match($re, $content, $match); $result = $match[0]; $parsed = new LuaParser($result); $slotitems = $parsed->toArray()['p.equipDataTb']; $table = []; foreach ($slotitems as $i => $item) { if (array_key_exists('中文名称', $item)) { $table[intval($i)] = $item['中文名称']; } else { $name = array_key_exists('日文名称', $item) ? $item['日文名称'] : $i; echo $name . " missing!\n"; } } Storage::disk('local')->put('slotitem/chinese_name/all.json', json_encode($table)); $this->info('Done.'); break; } }
public function uploadW9(Request $request, $link, $app_name, $aff_code) { $affiliate_row = Affiliate::where('external_link', '=', $link)->first(); if ($affiliate_row == null) { return redirect('error'); } //$user_infusionsoft = UserInfusionsoft::where('app_name','=', $app_name)->first(); $user_infusionsoft = $affiliate_row->infusionsoft_user; $app_infusionsoft = new iSDK(); if (!$app_infusionsoft->cfgCon($user_infusionsoft->app_name, $user_infusionsoft->app_apikey)) { return redirect('error'); } $file = $request->file('w9file'); if ($file) { $extension = $file->getClientOriginalExtension(); $mimeType = $file->getMimeType(); if (strtolower($extension) != 'pdf' || $mimeType != 'application/pdf') { return redirect(URL::to('aff/' . $link . '/' . $app_name . '/' . $aff_code))->with('error', 'You can upload pdf files only.'); } Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file)); $affiliate_row->w9_file_original_name = $file->getClientOriginalName(); $affiliate_row->w9_file = $file->getFilename() . '.' . $extension; $affiliate_row->save(); return redirect(URL::to('aff/' . $link . '/' . $app_name . '/' . $aff_code))->with('success', 'Congratulations! Your W9 is uploaded.'); } return redirect(URL::to('aff/' . $link . '/' . $app_name . '/' . $aff_code))->with('error', 'No file is selected.'); }
/** * Execute the console command. * * @return void */ public function handle() { $host = config('database.connections.mysql.host'); $database = config('database.connections.mysql.database'); $username = config('database.connections.mysql.username'); $password = config('database.connections.mysql.password'); $backupPath = config('backup.path'); $cloudStorage = config('backup.cloud-storage'); $cloudDisk = config('backup.cloud-disk'); $cloudPath = config('backup.cloud-path'); $keepLocal = config('backup.keep-local'); $path = config('backup.path'); $filename = $database . '_' . empty(trim($this->argument('filename'))) ? \Carbon\Carbon::now()->format('YmdHis') : trim($this->argument('filename')); $mysqldumpCommand = "mysqldump -e -f -h {$host} -u {$username} -p{$password} {$database} > {$backupPath}{$filename}.sql"; exec($mysqldumpCommand); $this->info('Backup completed!'); if ($cloudStorage) { $fileContents = file_get_contents("{$backupPath}{$filename}.sql"); Storage::disk($cloudDisk)->put("{$cloudPath}{$filename}.sql", $fileContents); if (!$keepLocal) { $rmCommand = "rm {$backupPath}{$filename}.sql"; exec($rmCommand); } $this->info('Backup uploaded to cloud storage!'); } }
/** * User registration * * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View */ public function register(Request $request) { if ($request->isMethod('post')) { $rules = ['first_name' => 'required', 'last_name' => 'required', 'position' => 'required', 'phone' => 'phone:AM', 'username' => 'required|unique:users,username', 'email' => 'required|email|unique:users,email', 'pass' => 'required|min:6|max:12', 'pass_confirmation' => 'required|min:6|max:12|same:pass', 'image' => 'mimes:jpeg,jpg,png']; Validator::make($request->all(), $rules)->validate(); $user = new User(); $user->first_name = $request->input('first_name'); $user->last_name = $request->input('last_name'); $user->position = $request->input('position'); $user->role_id = 2; if ($request->has('phone')) { $user->phone = $request->input('phone'); } if (!empty($request->file("image"))) { $generated_string = str_random(32); $file = $request->file("image")->store('uploads'); $new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension(); Storage::move($file, 'uploads/' . $new_file); $img = Image::make($request->file('image')); $img->crop(200, 200); $img->save(storage_path('app/public/uploads/' . $new_file)); $user->image = $new_file; } $user->username = $request->input('username'); $user->email = $request->input('email'); $user->password = Hash::make($request->input('pass')); $user->activation_token = str_random(32); $user->save(); return redirect('/'); } else { return view('site.auth.register'); } }
public function getFileName($file, $folder, $mode) { switch ($mode) { case 'default': $newFileName = str_random(10) . '.' . $file->getClientOriginalExtension(); break; case 'ai': $explodeFolder = explode('/', $folder); $lastFolder = end($explodeFolder); $files = Storage::files($folder); if (count($files) < 1) { $newFileName = $lastFolder . '-1' . '.' . $file->getClientOriginalExtension(); } else { sort($files, SORT_NATURAL); $fileName = explode('/', end($files)); $increment = explode('-', explode('.', end($fileName))[0])[1] + 1; $newFileName = $lastFolder . '-' . $increment . '.' . $file->getClientOriginalExtension(); } break; case 'replace': $newFileName = $file->getClientOriginalName(); break; } return $newFileName; }
/** * Destroy file * Path is relative to /app directory * * @param $filenamepath */ public function destroyFile($filenamepath) { if (Storage::has($filenamepath)) { return Storage::delete($filenamepath); } return true; }
protected static function boot() { parent::boot(); static::created(function ($model) { $storage = Storage::disk('gallery'); $path = 'galleries/' . str_slug($model->title); if (!$storage->exists($path)) { $storage->makeDirectory($path); return true; } return false; }); static::updating(function ($model) { $changed = $model->getDirty(); $original = $model->getOriginal(); $storage = Storage::disk('gallery'); $existsPath = 'galleries/' . $changed['slug']; if (!$storage->exists($existsPath)) { $oldPath = public_path() . '/gallery_assets/galleries/' . $original['slug']; $newPath = public_path() . '/gallery_assets/galleries/' . $changed['slug']; if (rename($oldPath, $newPath)) { $model->setAttribute('slug', $changed['slug']); return true; } } return false; }); static::deleting(function ($model) { $storage = Storage::disk('gallery'); $path = 'galleries/' . str_slug($model->title); if ($storage->exists($path)) { $storage->deleteDirectory($path); } }); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // $person = new User(); $person->first_name = $request->input('first-name'); $person->last_name = $request->input('last-name'); $person->email = $request->input('work-email'); $person->personal_email = $request->input('personal-email'); $person->password = Hash::make(uniqid()); $person->address1 = $request->input('address-one'); $person->address2 = $request->input('address-two'); $person->zip = $request->input('postcode'); $person->city = $request->input('city'); $person->state = $request->input('state'); $person->country = $request->input('country'); $person->dob = Carbon::createFromFormat('d/m/Y', $request->input('dob'))->toDateString(); $person->work_telephone = $request->input('work-telephone'); $person->personal_telephone = $request->input('personal-telephone'); $person->gender = $request->input('gender'); $person->save(); // Placeholder face until one is submitted $path = 'people/' . $person->id . '/face.jpg'; \Illuminate\Support\Facades\Storage::put($path, file_get_contents('http://api.adorable.io/avatar/400/' . md5($person->id . $person->email . Carbon::now()->getTimestamp()) . '')); $person->save(); // Default job position $person->jobPositions()->attach(1, ['primary' => true]); // Default role $person->roles()->attach(1, ['primary' => true]); return redirect()->intended('/people/'); }
public function getBaseUrl($file) { switch (Storage::getDefaultDriver()) { case 'local': return Storage::getDriver()->getAdapter()->getPathPrefix() . '/' . $file->id . '.' . $file->extension; } }
public static function lists() { $templates = Storage::directories('resources/views/vendor/front'); return array_map(function ($template) { return basename($template); }, $templates); }
/** * Save new email * * @param Request $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function updateEmail(Request $request) { $this->validate($request, ['email' => 'required|email']); $email = $request->get("email"); Storage::put('admin.txt', $email); return redirect("/"); }
public function putContent(Request $request) { $contents = $request->all(); $file = Storage::put('filter.txt', $contents['keywords']); flash()->success('修改成功'); return redirect()->back(); }
/** * 文件上传 * @throws \Exception */ public function upload() { // 要上传的空间 $bucket = "genffy"; // 生成上传 Token $token = self::auth()->uploadToken($bucket); // 要上传文件的本地路径 $floder = Storage::disk("local"); $filePath = $floder->getDriver()->getAdapter()->getPathPrefix() . "头像.png"; // 上传到七牛后保存的文件名 $key = md5($filePath) . ".png"; // 初始化 UploadManager 对象并进行文件的上传。 $uploadMgr = new UploadManager(); list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath); echo "\n====> putFile result: \n"; if ($err !== null) { var_dump($err); } else { // 返回下载链接 $time = time() + 7 * 24 * 60 * 60; $url = self::QI_NIU_DOMAIN . $ret["key"] . "?e={$time}"; $sign = hash_hmac('sha1', $url, self::getKey("secret"), true); $token = self::getKey("access") . ":" . self::urlsafe_base64_encode($sign); $realUrl = $url . "&token={$token}"; echo "<a href='{$realUrl}' target='_blank'>头像</a>"; } }