public function excluir($id) { $this->post = Post::where('id', $id)->first(); Storage::delete($this->post->id . '.jpg'); $this->post->delete(); return redirect()->route('dashboard'); }
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); } } }
/** * Destroy file * Path is relative to /app directory * * @param $filenamepath */ public function destroyFile($filenamepath) { if (Storage::has($filenamepath)) { return Storage::delete($filenamepath); } return true; }
/** * @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 excluir($id) { $aviso = new Aviso(); $aviso = Aviso::where('id', $id)->first(); $aviso->delete(); Storage::delete($aviso->id . 'aviso.jpg'); return redirect()->route('avisos'); }
protected function isFileExist() { $oe = $this->info->containmentAction->objective_evidence; if ($this->isNotEmpty($this->info->containmentAction) && $this->isExist($this->directory($oe))) { Storage::delete($this->directory($oe)); } return $this; }
public function delete($filename, $isLocal = false) { if ($isLocal) { File::delete(storage_path('app') . '/' . config('images.path') . $filename); } else { Storage::delete(config('images.path') . $filename); } }
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; }
/** * Bootstrap the application services. * * @return void */ public function boot() { $configPath = __DIR__ . '/config/connectionloader.php'; $migrationPath = __DIR__ . '/migration/2016_05_02_000000_create_connection_loader_table.php'; /** * Copy the default configuration file and migration file when user runs php artisan vendor:publish */ $this->publishes([$configPath => config_path('/connectionloader.php')], 'config'); $this->publishes([$migrationPath => database_path('/migrations/2016_05_02_000000_create_connection_loader_table.php')], 'migration'); if ($this->app['config']->get('connectionloader.enabled')) { if (!$this->app['config']->get('connectionloader.enabled')) { return; } $connection = $this->app['config']->get('connectionloader.connection'); $table = $this->app['config']->get('connectionloader.table'); $check = $this->app['config']->get('connectionloader.check_enabled'); if (!(isset($connection) && isset($table) && isset($check))) { \error_log('Invalid connection or table specified in configuration file'); return; } /** * Function to gather database connections from database and table provided * in configuration file. Compiles into file that returns an array. * Function returns path to the temporary file. */ $fileName = ConnectionLoader::getConnections($connection, $table); if ($fileName == null) { \error_log('Error in returned file name value'); return; } $file_path = storage_path('app/' . $fileName); /** * Merge the returned configuration array into the existing database.connections * configuration key. */ $key = 'database.connections'; $config = $this->app['config']->get($key, []); $configSet = $this->app['config']->set($key, array_merge(require $file_path, $config)); /** * Now to delete the temporary file created during the process */ $result = Storage::delete($fileName); if ($result === false) { \error_log('Failed to delete ' . storage_path() . $fileName); \error_log('Trying once more'); $result = Storage::delete($fileName); if ($result === true) { \error_log(storage_path() . $fileName . ' Deleted successfully'); return; } \error_log('Failed to delete twice, delete manually ' . storage_path() . $fileName); return; } ConnectionLoader::checkConnections($connection, $table, $check); } }
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 deleteApoyo($filename) { $archivo = $this->descargar($filename); $exists = Storage::disk('local')->exists($archivo->filename); if ($exists) { Storage::delete($archivo->filename); $archivo->delete(); flash()->overlay('Ha sido borrado sactifactoriamente', 'El archivo ' . $archivo->filename); } }
public function borrar($filename) { $archivo = Fileentry::where('filename', '=', $filename)->firstOrFail(); $exists = Storage::disk('local')->exists($archivo->filename); if ($exists) { Storage::delete($archivo->filename); $archivo->delete(); flash()->overlay('Ha sido borrado sactifactoriamente', 'El archivo ' . $archivo->filename); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // IF there is a previously uploaded award image file, delete it if (Session::has('award_image_upload')) { Storage::delete(storage_path('app\\uploads') . '\\' . Session::get('award_image_upload')); Session::delete('award_image_upload'); } $award = Award::findOrFail($id); return view('award.edit')->with('award', $award); }
public function destroy($id) { $store = Store::find($id); if ($store->file_entries_id !== 0) { $entry = FileEntry::find($store->file_entries_id); Storage::delete($entry->filename); $entry->delete(); } $store->delete(); return response()->json(['id' => $id]); }
public function RemoveColumnAudioSample($syllabaryId, $columnId) { $column = SyllabaryColumnHeader::where('syllabary_id', '=', $syllabaryId)->where('id', '=', $columnId)->first(); try { Storage::delete($column->audio_sample); } catch (\Exception $e) { } $column->audio_sample = null; $column->save(); return redirect()->back(); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $model = Registro::findOrFail($id); try { Storage::delete($model->filename); } catch (Exception $e) { // The file was deleted on the server, someone should know about this... } $model->delete(); return redirect('registros')->with('message', 'Registro eliminado exitosamente!'); }
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; }
public function file($id) { $offer = $this->offer->findOrFail($id); $file = $offer->filename; $offer->fill(['filename' => ''])->save(); $store = Storage::delete('public/offers/' . $file); if ($store == 302) { $message = "File was deleted!"; } else { $message = "Something went wrong!"; } return redirect()->back()->with('status', $message); }
public function run() { $files = Storage::allFiles(); foreach ($files as $file) { Storage::delete($file); } $products = Product::all(); foreach ($products as $product) { $uri = str_random(12) . '_370x235.jpg'; Storage::put($uri, file_get_contents('http://lorempixel.com/futurama/370/235/')); Picture::create(['product_id' => $product->id, 'title' => $this->faker->name, 'uri' => $uri]); } }
public function zipAll() { $files = TFFile::where('state', '=', 'downloaded')->get(); $imageCount = TFFile::where('state', '=', 'downloaded')->where('type', '=', 'image')->count(); $videoCount = TFFile::where('state', '=', 'downloaded')->where('type', '=', 'video')->count(); if ($videoCount == 0 && $imageCount == 0) { Log::info('TFZipper : no file to be zipped.'); return; } $fileLocs = ""; $deleteLocs = []; foreach ($files as $file) { $deleteLocs[] = $file->location; $fileLocs .= ' ' . storage_path('app/' . $file->location); $file->state = 'zipped'; $file->save(); } $zipName = Carbon::now()->toDateString() . '.zip'; $zipLocs = 'zip/' . $zipName; $cmdPass = self::PASSWORD; $cmdTarget = storage_path('app/' . $zipLocs); $cmdLocs = $fileLocs; $cmd = ""; $sys = php_uname('s'); if ($sys == 'Windows NT') { $cmd = $this->rarCmd; } else { if ($sys == 'Linux') { $cmd = $this->zipCmd; } } $cmd = sprintf($cmd, $cmdPass, $cmdTarget, $cmdLocs); if ($sys == 'Windows NT') { $cmd = str_replace("/", "\\", $cmd); } $result = $this->runCmd($cmd); if (false == $result) { return; } $zip = new TFZip(); $zip->state = 'zipped'; $zip->error = ''; $zip->name = $zipName; $zip->date = Carbon::now()->toDateString(); $zip->size = number_format(Storage::size($zipLocs) / 1024.0 / 1024.0, 2) . 'MB'; $zip->imageSize = $imageCount; $zip->videoSize = $videoCount; $zip->location = $zipLocs; $zip->save(); Storage::delete($deleteLocs); }
/** * 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')); } }
/** * @param File $file * @param $data * * @return File|false */ public function update(File $file, $data) { if (!is_null($file->path)) { $currentFilePath = $file->path; } $file->fill(array_merge($data, [File::PATH => FilesStorage::getFilesDirectory() . $data[File::CLIENT_ORIGINAL_NAME]])); $fileIsStored = Storage::put($file->path, file_get_contents($data[File::TEMPORARY_PATH])); if (!$fileIsStored || !$file->save()) { return false; } if (isset($currentFilePath)) { Storage::delete($currentFilePath); } return $file; }
/** * TODO: We really need ot look at rethinking the way we do the image/media stuff * * @param string $image */ public function destroy($image) { if (str_contains($image, '__cover__')) { $type = explode('-', $image)[0]; $typeClass = '\\Flashtag\\Posts\\' . ucfirst($type); $model = $typeClass::where('cover_image', $image)->first(); $model->update(['cover_image' => null]); } elseif (substr($image, 0, 5) === "post-") { $post = Post::where('image', $image)->first(); $post->update(['image' => null]); } else { $media = Media::where('url', $image)->first(); $media->delete(); } Storage::delete('/public/images/media/' . $image); }
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'); }
/** @test */ public function it_creates_new_file() { $dbFileRepository = new DbFileRepository(); $expectedFileName = 'dummy_logo.png'; $expectedFilePath = FilesStorage::getFilesDirectory() . $expectedFileName; $expectedFile = factory(File::class, 'without_storage')->make(['path' => $expectedFilePath, 'client_original_name' => $expectedFileName]); $requestData = array_only($expectedFile->toArray(), $expectedFile->getFillable()); $requestData[File::CLIENT_ORIGINAL_NAME] = $expectedFileName; $tempFilePath = [File::TEMPORARY_PATH => storage_path('app/testing/dummy_logo.png')]; $this->notSeeInDatabase('files', $requestData); if (Storage::exists($expectedFilePath)) { Storage::delete($expectedFilePath); } $this->assertFalse(Storage::exists($expectedFilePath)); $this->assertNotFalse($file = $dbFileRepository->store(array_merge($requestData, $tempFilePath))); $this->seeInDatabase('files', $requestData + [File::PATH => $expectedFilePath]); $this->assertTrue(Storage::exists($expectedFilePath)); }
/** * Delete a file from the filesystem. * * @param string $filename * @param array $options * * @return bool */ public function deleteUpload($filename, array $options = []) { // Reset variables. $this->resetUploadVariables(); // Setup options. $this->setupUploadOptions($options); // Remove the Local URI from filename. if ($this->disk == 'local') { $filename = str_replace($this->localUri, '', $filename); } // Remove the Amazon S3 URI from filename. if ($this->disk == 's3') { $filename = str_replace($this->amazonUri, '', $filename); } // Delete file. $this->filesystem->delete($filename); return true; }
public static function zipOneDay(Carbon $date) { $begin = $date->copy()->setTime(0, 0, 0); $end = $date->copy()->setTime(23, 59, 59); $deleteLocs = []; $videoLocs = []; $videos = Video::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get(); foreach ($videos as $video) { $deleteLocs[] = $video->location; $videoLocs[] = storage_path('app/' . $video->location); $video->state = 'zipped'; $video->save(); } $imageLocs = []; $images = Image::where('state', '=', 'downloaded')->where('updated_at', '>=', $begin->toDateTimeString())->where('updated_at', '<=', $end->toDateTimeString())->get(); foreach ($images as $image) { $deleteLocs[] = $image->location; $imageLocs[] = storage_path('app/' . $image->location); $image->state = 'zipped'; $image->save(); } $locs = array_merge($videoLocs, $imageLocs); if (count($locs) == 0) { Log::info('TumblrZip : no file to be ziped.'); return; } $zipName = $begin->toDateString() . '.zip'; $zipLocs = 'zips/' . $zipName; $zippy = Zippy::load(); $zippy->create(storage_path('app/' . $zipLocs), $locs); $zip = new Zip(); $zip->state = 'ziped'; $zip->error = ''; $zip->name = $zipName; $zip->date = $begin->toDateString(); $zip->size = number_format(Storage::size($zipLocs) / 1024.0 / 1024.0, 2) . 'MB'; $zip->imageSize = count($imageLocs); $zip->videoSize = count($videoLocs); $zip->location = $zipLocs; $zip->save(); Storage::delete($deleteLocs); }
public function image($request, $product) { if ($request->input('supImag') == 'true') { Storage::delete($product->picture->uri); $product->picture->delete(); } if ($request->file('thumnail')) { if ($product->picture) { Storage::delete($product->picture->uri); $product->picture->delete(); } $name = $request->input('name'); $im = $request->file('thumnail'); $ext = $im->getClientOriginalExtension(); $num_prod = $product->id; $num_prod = intval($num_prod); $uri = str_random(12) . '.' . $ext; $im->move(env('UPLOAD_PATH', './uploads'), $uri); Picture::create(['product_id' => $num_prod, 'size' => $im->getClientSize(), 'uri' => $uri, 'type' => $ext, 'title' => $name]); } }
/** * 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); } }
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; } } } }