/** * Delete the file with the given path * * @param string $file * * @return boolean * @throws FileDoesNotExists */ public function fileDelete($file) { if (!File::isFile($this->getPath($file))) { throw new FileDoesNotExists(); } return File::delete($this->getPath($file)); }
/** * @param \Onyx\Destiny\Objects\Hash $hash * @param string $index * @return bool */ public static function saveImageLocally($hash, $index = 'extra') { // BUG: Can't use variable object indexes implicitly // $hash->{$index} should work but doesn't // map the index explicitly with the attributes dumped into $bug $bug = $hash->getAttributes(); $url = "https://bungie.net" . $bug[$index]; $name = $index != 'extra' ? '_bg' : null; $name = $hash->hash . $name; // Make sure we aren't trying to save something that isn't an image // We only need this check because we cheat and store all hash related objects // in one table. This means we have crazy cheats to get things done. if (strlen($bug[$index]) < 5) { return false; } $location = public_path('uploads/thumbs/'); $filename = $name . "." . pathinfo($bug[$index], PATHINFO_EXTENSION); if (File::isFile($location . $filename)) { return true; } if ($hash instanceof Hash) { $manager = new ImageManager(); try { $img = $manager->make($url); $img->save($location . $filename); } catch (NotReadableException $e) { Log::error('Could not download: ' . $url); } return true; } }
/** * Download file * * @return Response */ public function download_file($filename) { $file = public_path() . "/uploads/{$filename}"; if (File::isFile($file)) { $headers = array('Content-Type: application/pdf', 'application/octet-stream', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/pdf'); return Response::download($file, $filename, $headers); } }
/** * Register the application services. * * @return void */ public function register() { foreach ($this->helpers as $helper) { $helper_path = app_path() . '/Helpers/' . $helper . '.php'; if (File::isFile($helper_path)) { require_once $helper_path; } } }
/** * Similar to addMessagesToExport(), but does not * register an array of message keys, but the * messages of a whole language file (one of the * PHP files in app/lang). * * @param string $filePath Path to the message file. * @param string $prefix Optional. Prefix to prepend before the message keys. * @return void */ public function addMessageFileToExport($filePath, $prefix = "") { if (!File::isFile($filePath)) { throw new FileNotFoundException("File not found: {$filePath}"); } $messages = (require_once $filePath); $prefix = $this->prefix($prefix); $prefix .= preg_replace('/\\.php$/i', '', basename($filePath)) . '.'; $this->messagesToExport = array_unique(array_merge($this->messagesToExport, $this->resolveMessageArrayToMessageKeys($messages, $prefix))); }
public function deletePhoto($path) { $photoPath = public_path('images/uploads/' . $path); try { if (File::isFile($photoPath)) { File::delete($photoPath); } Photo::wherePath($path)->delete(); } catch (Exception $e) { } }
protected function checkFile($routePath, $fileName) { $routeFile = $routePath . '/' . $fileName . '.php'; if (File::isFile($routeFile)) { if ($this->confirm('Do you wish to overwrite the existing file? [yes|no]')) { File::delete($routeFile); } else { return $this->info('Alright, no files touched!'); } } return $routeFile; }
public function __construct($filePath) { parent::__construct(); if (!File::isFile($filePath)) { throw new Exception("Cannot read file: {$filePath}"); } $fileContent = file_get_contents($filePath); $this->setContent($fileContent); $lastModified = new DateTime(); $lastModified->setTimestamp(File::lastModified($filePath)); $this->setLastModified($lastModified); $this->isNotModified(App::make('request')); }
public function resize($width, $height) { $useStorage = Config::get('astroanu.imagecache.usestorage'); if ($useStorage) { $inputDisk = Storage::disk(Config::get('astroanu.imagecache.paths.input')); $outputDisk = Storage::disk(Config::get('astroanu.imagecache.paths.output')); if (!$inputDisk->exists($this->folder . '/' . $this->filename)) { return false; } if (is_null($width) || is_null($height)) { return $this->imagine->load($inputDisk->get($this->folder . '/' . $this->filename))->show('jpg'); } if ($outputDisk->exists($this->folder . '/' . $this->filename)) { return $this->imagine->load($outputDisk->get($this->folder . '/' . $this->filename))->show('jpg'); } $size = new \Imagine\Image\Box($width, $height); $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND; if (!$outputDisk->exists($this->folder)) { $outputDisk->makeDirectory($this->folder); } $tmp = storage_path() . '\\tmp_' . $this->filename; $this->outputFile = $this->folder . '/' . $width . '-' . $height . '_' . $this->filename; $tmpImage = $this->imagine->load($inputDisk->get($this->folder . '/' . $this->filename))->thumbnail($size, $mode)->save($tmp, array('quality' => Config::get('astroanu.imagecache.defaults.jpgquality'))); $outputDisk->put($this->outputFile, File::get($tmp)); unlink($tmp); return $this->imagine->load($outputDisk->get($this->outputFile))->show('jpg'); } else { // to be removed $outputDir = Config::get('astroanu.imagecache.paths.output') . '/' . $this->folder; $inputDir = Config::get('astroanu.imagecache.paths.input') . '/' . $this->folder; $inputFile = $inputDir . '/' . $this->filename; if (!file_exists($inputFile)) { return false; } if (is_null($width) || is_null($height)) { return $this->imagine->open($inputFile)->show('jpg'); } $this->outputFile = $outputDir . '/' . $width . '-' . $height . '_' . $this->filename; if (File::isFile($this->outputFile)) { return $this->imagine->open($this->outputFile)->show('jpg'); } $size = new \Imagine\Image\Box($width, $height); $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND; if (!File::isDirectory($outputDir)) { File::makeDirectory($outputDir); } return $this->imagine->open($inputFile)->thumbnail($size, $mode)->save($this->outputFile, array('quality' => Config::get('astroanu.imagecache.defaults.jpgquality')))->show('jpg'); } }
public function deleteRelatedPhotos($id, $model) { $model = 'App\\' . $model; $photos = Photo::where('imageable_type', $model)->where('imageable_id', $id); if (count($photos) > 0) { foreach ($photos->get() as $photo) { $photoPath = public_path('images/uploads/' . $photo->path); try { if (File::isFile($photoPath)) { File::delete($photoPath); } } catch (Exception $e) { } } $photos->delete(); } }
/** * Run the settings table seeder * @param string $master */ public function settingsSeeder($master = 'master') { $cli_path = 'config/ticketit.php'; // if seeder run from cli, use the cli path $provider_path = '../config/ticketit.php'; // if seeder run from provider, use the provider path $config_settings = []; $settings_file_path = false; if (File::isFile($cli_path)) { $settings_file_path = $cli_path; } elseif (File::isFile($provider_path)) { $settings_file_path = $provider_path; } if ($settings_file_path) { $config_settings = (include $settings_file_path); File::move($settings_file_path, $settings_file_path . '.backup'); } $seeder = new SettingsTableSeeder(); $config_settings['master_template'] = $master; $seeder->config = $config_settings; $seeder->run(); }
/** * Resolve whether the file exists and if it already does, change the file name. * @param string $folder * @param $file * @param bool $enableObfuscation * @return array */ public function resolveFileName($folder, UploadedFile $file, $enableObfuscation = true) { if (!isset($file->fileSystemName)) { $file->fileSystemName = $file->getClientOriginalName(); } if (static::$app['config']->get('cabinet::obfuscate_filenames') && $enableObfuscation) { $fileName = basename($file->fileSystemName, $file->getClientOriginalExtension()) . '_' . md5(uniqid(mt_rand(), true)) . '.' . $file->getClientOriginalExtension(); $file->fileSystemName = $fileName; } else { $fileName = $file->fileSystemName; } // If file exists append string and try again. if (File::isFile($folder . $fileName)) { // Default file postfix $i = '0000'; // Get the file bits $basename = $this->getBasename($file); $basenamePieces = explode('_', $basename); // If there's more than one piece then let see if it's our counter. if (count($basenamePieces) > 1) { // Pop the last part of the array off. $last = array_pop($basenamePieces); // Check to see if the last piece is an int. Must be 4 long. This isn't the best, but it'll do in most cases. if (strlen($last) == 4 && (is_int($last) || ctype_digit($last))) { // Add one, which converts this string to an int. Gotta love PHP ;) $last += 1; // Prepare to add the proper amount of 0's in front $b = 4 - strlen($last); $i = $last; for ($c = 1; $c <= $b; $c++) { $i = '0' . $i; } } else { // Put last back on the array array_push($basenamePieces, $last); } // Put the pieces back together without the postfix. $basename = implode('_', $basenamePieces); } // Create the filename $file->fileSystemName = $basename . '_' . $i . '.' . $file->getClientOriginalExtension(); list($folder, $file) = $this->resolveFileName($folder, $file, false); } return array($folder, $file); }
/** * Search for the assets in the passed path * taking into account configured base paths (workbench, vendor, etc) * * @param string $path The path to search * @param string $package The package the assets belong to * @return array|null The array of SplFileInfo objects or null */ protected function findAssets($path, $package) { $paths = array_merge($this->paths, $this->config->get('asset::search_paths')); foreach ($paths as $searchPath) { $fullPath = base_path() . $searchPath . '/' . $package . '/' . $path; if (File::isDirectory($fullPath)) { return File::allFiles($fullPath); } elseif (File::isFile($fullPath)) { return Finder::create()->depth(0)->name(basename($fullPath))->in(dirname($fullPath)); } } }
/** * Check path is file * * @param string $filePath File path * @return boolean True or false */ private function isFile($filePath) { return File::isFile($filePath); }
/** * Find the related photo on the given Model, If there's an existing * photo, we will loop through them and then delete them one by one. * And finally, we will delete it's record from the "photos" table */ public function deleteExistingPhotos($id, $model) { $model = 'App\\' . $model; $oldPhoto = Photo::where('imageable_type', $model)->where('imageable_id', $id); if (count($oldPhoto) > 0) { foreach ($oldPhoto->get() as $photo) { $oldPhotoPath = public_path('images/uploads/' . $photo->path); if (File::isFile($oldPhotoPath)) { File::delete($oldPhotoPath); } } $oldPhoto->delete(); } }
public function resize($filename, $sizeString) { // We can read the output path from our configuration file. $outputDir = Config::get('assets.images.paths.output'); // Create an output file path from the size and the filename. $outputFile = $outputDir . '/' . $sizeString . '_' . $filename; // If the resized file already exists we will just return it. if (File::isFile($outputFile)) { return File::get($outputFile); } // File doesn't exist yet, so we will resize the original. $inputDir = Config::get('assets.images.paths.input'); $inputFile = $inputDir . '/' . $filename; // Get the width and the height of the chosen size from the Config file. $sizeArr = Config::get('assets.images.sizes.' . $sizeString); $width = $sizeArr['width']; $height = $sizeArr['height']; // We want to crop the image so we set the resize mode and size. $size = new \Imagine\Image\Box($width, $height); $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND; // Create the output directory if it doesn't exist yet. if (!File::isDirectory($outputDir)) { File::makeDirectory($outputDir); } // Open the file, resize it and save it. $this->imagine->open($inputFile)->thumbnail($size, $mode)->save($outputFile, array('quality' => 90)); // Return the resized file. return File::get($outputFile); }