/** * 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)); }
public function retrieveFile(Submission $submissions, $file) { $form = $submissions->formdefinition()->first(); if ($submissions->group()->users()->get()->contains(Auth::user())) { //$file = Storage::get("form/".$form->id."/".$file); $filepath = "form/" . $form->id . "/" . $file; //Storage::get(form/) // if(Storage::exists($filepath)){ /* if(copy($filepath,"/var/www/calwebtool/public/downloads/".$file)){ return respones()->file("downloads/".$file); } //Storage::copy($filepath,"downloads/".$file); return response()->file("downloads/".$file); //} /*else{ flash()->overlay("The file does not exist.","Not Found"); return redirect()->back(); }*/ if (Storage::exists($filepath)) { if (Storage::exists("downloads/" . $file)) { Storage::delete("downloads/" . $file); } Storage::copy($filepath, "downloads/" . $file); return response()->download("downloads/" . $file); } } }
/** * Read last visited timestamp from file and return * timestamp as Carbon object or return zero. * * @return int|\Carbon\Carbon */ protected function getLastVisit() { if (Storage::exists('visited.txt')) { return Carbon::createFromTimestamp(Storage::get('visited.txt')); } return 0; }
/** * 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)); }
/** * Norwegian map with municipalities where Alternativet is represented highlighted */ public function membersMapNorway() { $data = ""; if (!Storage::exists('members-norway-map.svg') || Storage::lastModified('members-norway-map.svg') <= time() - 60 * 60 * 24) { $svg = simplexml_load_file(base_path() . '/resources/svg/Norway_municipalities_2012_blank.svg'); // Determine which municipalities there are members in $result = DB::select(DB::raw("\n select postal_areas.municipality_code, count(*) as count\n from users\n left join postal_areas\n on (users.postal_code = postal_areas.postal_code)\n group by municipality_code")); $municipalities = []; foreach ($result as $row) { if ($row->municipality_code) { $municipalities[] = $row->municipality_code; } } foreach ($svg->g as $county) { foreach ($county->path as $path) { if (in_array($path['id'], $municipalities)) { // There are members in this municipality $path['style'] = 'fill:#0f0;fill-opacity:1;stroke:none'; } else { $path['style'] = 'fill:#777;fill-opacity:1;stroke:none'; } } } $data = $svg->asXML(); Storage::put('members-norway-map.svg', $data); } if (empty($data)) { $data = Storage::get('members-norway-map.svg'); } return response($data)->header('Content-Type', 'image/svg+xml'); }
public function handle($payload) { $this->folder = $payload['folder']; $this->cleanUp(); if (isset($payload['bucket'])) { Config::set('S3_BUCKET', $payload['bucket']); } if (isset($payload['region'])) { Config::set('S3_REGION', $payload['region']); } if (isset($payload['secret'])) { Config::set('S3_SECRET', $payload['secret']); } if (isset($payload['key'])) { Config::set('S3_KEY', $payload['key']); } if (isset($payload['destination'])) { $this->thumbnail_destination = $payload['destination']; } else { $this->thumbnail_destination = base_path("storage"); } if (!Storage::exists($this->thumbnail_destination)) { Storage::makeDirectory($this->thumbnail_destination, 0755, true); } $files = Storage::disk('s3')->allFiles($this->folder); Log::info(print_r($files, 1)); $this->getAndMake($files); $this->uploadFilesBacktoS3(); $this->cleanUp(); }
/** * Generate random string for a filename * * @param string $ext * @param string $location * @return string */ private function generateFilename() { $filename = str_random(100) . "." . $this->extension; if (Storage::exists($this->folder . '/' . $filename)) { $this->generateFilename(); } return $filename; }
/** * Bind data to the view. * * @param View $view * * @return void */ public function compose(View $view) { $locale = app()->getLocale(); $filename = Request::route()->getName() . '.md'; $filepath = 'userhelp' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $filename; $help = Storage::exists($filepath) ? Markdown::convertToHtml(Storage::get($filepath)) : ''; $view->with('help', $help); }
/** * Generate random string for a filename * * @param string $ext * @param string $location * @return string */ public function createFilename($ext, $location) { $filename = str_random(100) . ".{$ext}"; if (Storage::exists("{$location}/{$filename}")) { $this->createFilename($ext, $location); } return $filename; }
/** * @param $id * @return array */ public function delete($id) { $obj = $this->rep->find($id); if (Storage::exists($obj->id . '.' . $obj->extension)) { Storage::delete($obj->id . '.' . $obj->extension); } return parent::delete($id); }
public function deleteFile($id) { $pf = $this->repository->find($id); $filename = $pf->name . "." . $pf->extension; if (Storage::exists($filename) && $this->delete($id)) { return Storage::delete($filename); } return true; }
/** * Save the file * Fire FileWasSaved Event * */ public function handle() { if (Storage::exists($this->getDefaultFileName())) { if (!$this->force) { return; } } $this->saveFile(); event(new FileWasSaved($this->filename, $this->force)); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($path) { $entry = FileEntry::where('filename', '=', $path)->first(); if ($entry == null || !Storage::exists($path)) { return response('NotFound', 404); } else { $file = Storage::get($entry->filename); return response($file)->header('Content-Type', $entry->mime); } }
public function postEliminar() { $id = Input::get('id'); $medio = Input::get('medio'); if (Storage::exists($medio)) { Storage::delete($medio); } Medio::find(Input::get('id'))->fill(Input::all())->delete(); return response()->json(["mensaje" => "eliminado"]); }
public function get($filename) { $path = config('images.path') . $filename; if (!Storage::exists($path)) { throw new ImageNotFoundHttpException(); } $data = Storage::get($path); $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $data); return Response::make($data)->header('Content-Type', $mime)->header('Content-Length', strlen($data)); }
public function upload($path, $filename, $file) { // Verifica se o diretório permite escrita if (!File::isWritable(storage_path('app/' . $path))) { return ['cod' => '0', 'msg' => '[ERRO] Diretorio sem permissão de escrita.']; } if (Storage::exists('app/' . $path . '/' . $filename)) { return ['cod' => '0', 'msg' => '[ERRO] Já existe um arquivo com este nome.']; } return Storage::disk('local')->put($path . $filename, file_get_contents($file->getRealPath())); }
public function deleteFile($id) { $pf = $this->repository->find($id); $filename = $pf->name . "." . $pf->extension; if (Storage::exists($filename)) { Storage::delete($filename); } if (!Storage::exists($filename)) { return parent::delete($id); } return false; }
/** * Increment the filename until it is unique. * * @param string $filename * @param string $directory * @return string|string */ static function incrementFilename($filename, $directory) { $extension = substr($filename, strrpos($filename, '.')); $baseFilename = substr($filename, 0, strrpos($filename, '.')); $filepath = $directory . $filename; if (Storage::exists($filepath)) { $number = 0; do { $filename = $baseFilename . '-' . ++$number . $extension; $filepath = $directory . $filename; } while (Storage::exists($filepath)); } return $filename; }
/** * Site settings * * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function index(Request $request) { $settings = Settings::getSettings(); if ($request->isMethod('post')) { $rules = ['url' => 'required', 'email' => 'required|email', 'title' => 'required', 'desc' => 'required', 'keys' => 'required', 'logo' => 'mimes:jpeg,png', 'favicon' => 'mimes:jpeg,png']; Validator::make($request->all(), $rules)->validate(); $settings->url = $request->input('url'); $settings->email = $request->input('email'); $settings->title = $request->input('title'); $settings->desc = $request->input('desc'); $settings->keys = $request->input('keys'); if (!empty($request->file("logo"))) { if (Storage::exists('uploads/' . $settings->logo)) { Storage::delete('uploads/' . $settings->logo); } $generated_string = str_random(32); $file = $request->file("logo")->store('uploads'); $new_file = $generated_string . '.' . $request->file("logo")->getClientOriginalExtension(); Storage::move($file, 'uploads/' . $new_file); $img = Image::make($request->file('logo')); $img->crop(200, 26); $img->save(storage_path('app/public/uploads/' . $new_file)); $settings->logo = $new_file; } if (!empty($request->file("favicon"))) { if (Storage::exists('uploads/' . $settings->favicon)) { Storage::delete('uploads/' . $settings->favicon); } $generated_string = str_random(32); $file = $request->file("favicon")->store('uploads'); $new_file = $generated_string . '.' . $request->file("favicon")->getClientOriginalExtension(); Storage::move($file, 'uploads/' . $new_file); $img = Image::make($request->file('favicon')); $img->crop(16, 16); $img->save(storage_path('app/public/uploads/' . $new_file)); $settings->favicon = $new_file; } if ($request->input('maintenance') == '0') { Artisan::call('down'); } else { Artisan::call('up'); } $settings->maintenance = $request->input('maintenance'); $settings->save(); return redirect()->back(); } else { return view('admin.settings', compact('settings')); } }
/** * Generates a filename and check that file is not exists. * * @param int $i * @return string */ protected function getCompleteFilename($i = 0) { $filename = $this->filename; // interrupt filename if ($i !== 0) { $filename .= '_' . $i; } $completeFilename = $filename . '.' . $this->extension; // file exists if (Storage::exists($this->getFolder() . $completeFilename)) { $i++; return $this->getCompleteFilename($i); } return $completeFilename; }
public function setup() { $user = Auth::user(); $email = $user->email; $images = DB::table('images')->where('email', '=', $email)->orderBy('id', 'asc')->get(); //var_dump($images); foreach ($images as $image) { $path = $email . "/" . $image->name; if (Storage::exists($path)) { Storage::delete($path); } $file = Storage::put($path, $image->image); var_dump($image->image); echo "{$path} created!"; } return redirect('home'); }
/** * Show the requestet file and calculate headers * * @param string $filename * @return mixed */ public function show($filename) { $path = getUploadDirectory() . '/' . $filename . '/default'; if (Storage::exists($path)) { clearstatcache(); $file = Storage::get($path); $lastModified = filemtime(storage_path('/app/') . $path); $etagFile = md5_file(storage_path('/app/') . $path); $etagHeader = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false; $responseCode = 200; if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModified || $etagHeader == $etagFile) { $responseCode = 304; } return response($file, $responseCode)->header('Content-Type', getFileContentTypeByFilename($filename))->header('Last-Modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT')->header('Etag', $etagFile)->header('Cache-Control', 'public'); } abort(404); }
/** * @return Boek[] * @throws Exception */ public function retreive() { if (Storage::exists($this->database)) { $objectedBoeken = json_decode(Storage::get($this->database)); if ($objectedBoeken || is_array($objectedBoeken)) { $boeken = []; foreach ($objectedBoeken as $boekObject) { $boek = new Boek(); $boek->setId($boekObject->id)->setIsbn($boekObject->isbn)->setTitel($boekObject->titel)->setGewicht((int) $boekObject->gewicht)->setIntroductie($boekObject->introductie); $boeken[$boek->getId()] = $boek; } return $boeken; } else { throw new Exception('Database error: wrong file format'); } } return []; }
/** * Get the URI path of the file. * * @param string $filename * * @return null|string */ protected function getUploadUri($filename) { // Setup the default variable value. $path = null; // If the file exists, get the URI for it. if ($this->filesystem->exists($filename)) { // If filesystem disk is Local, get the public_path of the file located locally. if ($this->disk == 'local') { $url = config('app.url') . '/uploads'; $path = "{$url}/{$filename}"; } // If filesystem disk is Amazon S3, get the actual URI for the file located in the Amazon S3 bucket. if ($this->disk == 's3') { $path = $this->filesystem->getDriver()->getAdapter()->getClient()->getObjectUrl(config('filesystems.disks.s3.bucket'), $filename); } } return $path; }
/** * Restore attributes collection * @return Collection */ private function getCollection() { if ($this->__laCollection == null) { $cached_collection = Cache::rememberForever($this->getCacheQuequeMask(), function () { if (config('lauser.save_type') == 'file') { $path = $this->getLaUserFilePathById($this->id); if (Storage::exists($path)) { return new Collection(json_decode(Storage::get($path), true)); } else { return new Collection([]); } } else { return new Collection($this->getLaUserAttributesFromDatabase($this->id)); } }); $this->__laCollection = $cached_collection; } return $this->__laCollection; }
public function storeFromUrl($url, $path, $name) { $counter = 1; if (Storage::exists($path . '/' . $name . '.' . pathinfo($url, PATHINFO_EXTENSION))) { while (Storage::exists($path . '/' . $name . '-' . $counter . '.' . pathinfo($url, PATHINFO_EXTENSION))) { $counter++; } $name = $name . '-' . $counter; } $file = file_get_contents($url); if (Storage::put($path . '/' . $name . '.' . pathinfo($url, PATHINFO_EXTENSION), $file)) { $this->filename = $path . '/' . $name . '.' . pathinfo($url, PATHINFO_EXTENSION); $this->mime = Storage::mimeType($path . '/' . $name . '.' . pathinfo($url, PATHINFO_EXTENSION)); $this->original_filename = $url; $this->save(); return $this->id; } else { return false; } }
/** @test */ public function it_updates_a_file() { $dbFileRepository = new DbFileRepository(); $expectedClientOriginalName = 'dummy_logo3.png'; $expectedFilePath = FilesStorage::getFilesDirectory() . $expectedClientOriginalName; $expectedFile = factory(File::class, 'without_storage')->make(['path' => $expectedFilePath, 'client_original_name' => $expectedClientOriginalName]); $expectedTemporaryPath = storage_path('app/testing/dummy_logo.png'); $requestData[File::NAME] = $expectedFile->name; $requestData[File::DESCRIPTION] = $expectedFile->description; $requestData[File::CLIENT_ORIGINAL_NAME] = $expectedClientOriginalName; $tempFilePath = [File::TEMPORARY_PATH => $expectedTemporaryPath]; $currentFile = factory(File::class)->create(); $oldFilePath = $currentFile->path; $this->assertTrue(Storage::exists($currentFile->path)); $this->assertFalse(Storage::exists($expectedFilePath)); $this->assertNotFalse($dbFileRepository->update($currentFile, array_merge($requestData, $tempFilePath))); $this->seeInDatabase('files', [File::NAME => $expectedFile->name, File::DESCRIPTION => $expectedFile->description, File::PATH => $expectedFilePath, File::CLIENT_ORIGINAL_NAME => $expectedClientOriginalName, File::SLUG => 'dummy-logo3-png']); $this->assertFalse(Storage::exists($oldFilePath)); $this->assertTrue(Storage::exists($expectedFilePath)); }
/** * Delete an old profile image and replace it with a new one. * @param $userId */ public function approveNewImage($userId) { $sourceFilename = \App::environment() . '/user-photo/' . md5($userId) . '-new.png'; $sourceThumbFilename = \App::environment() . '/user-photo/' . md5($userId) . '-thumb-new.png'; $targetFilename = \App::environment() . '/user-photo/' . md5($userId) . '.png'; $targetThumbFilename = \App::environment() . '/user-photo/' . md5($userId) . '-thumb.png'; if (Storage::exists($targetFilename)) { Storage::delete($targetFilename); } if (Storage::exists($targetThumbFilename)) { Storage::delete($targetThumbFilename); } Storage::move($sourceFilename, $targetFilename); Storage::move($sourceThumbFilename, $targetThumbFilename); if (Storage::exists($sourceFilename)) { Storage::delete($sourceFilename); } if (Storage::exists($sourceThumbFilename)) { Storage::delete($sourceThumbFilename); } }
private function getAttachments($invoiceId) { // Invoice $attachments = [storage_path('app/' . $invoiceId . '-invoice.pdf')]; // Invoice without commission if (Storage::exists($invoiceId . '-invoice-x.pdf')) { $attachments[] = storage_path('app/' . $invoiceId . '-invoice-x.pdf'); } // Itinerary if (Storage::exists($invoiceId . '-itinerary.pdf')) { $attachments[] = storage_path('app/' . $invoiceId . '-itinerary.pdf'); } // Fright itinerary if (Storage::exists($invoiceId . '-flight.pdf')) { $attachments[] = storage_path('app/' . $invoiceId . '-flight.pdf'); } // Misc if (Storage::exists($invoiceId . '-misc.pdf')) { $attachments[] = storage_path('app/' . $invoiceId . '-misc.pdf'); } return $attachments; }
public function setFilenameAttribute($filename) { $oldFileName = !empty($this->attributes['filename']) ? $this->attributes['filename'] : ''; if (class_basename($filename) == 'UploadedFile') { $this->attributes['filename'] = self::genName($filename); $this->attributes['path'] = $this->attributes['filename']; Storage::disk('local')->put($this->attributes['filename'], FileFacade::get($filename)); if ($oldFileName && Storage::exists($oldFileName)) { Storage::delete($oldFileName); } } else { if (is_string($filename) && is_file($filename)) { $new_filename = basename($filename); } else { if ($filename && is_string($filename) && $oldFileName && $oldFileName != $filename) { Storage::move($oldFileName, $filename); } else { $this->attributes['filename'] = $filename; } } } }