/** * @return string */ public function getRename() { $old_name = Input::get('file'); $new_name = Input::get('new_name'); $file_path = parent::getPath('directory'); $thumb_path = parent::getPath('thumb'); $old_file = $file_path . $old_name; if (!File::isDirectory($old_file)) { $extension = File::extension($old_file); $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension; } $new_file = $file_path . $new_name; if (File::exists($new_file)) { return Lang::get('laravel-filemanager::lfm.error-rename'); } if (File::isDirectory($old_file)) { File::move($old_file, $new_file); return 'OK'; } File::move($old_file, $new_file); if ('Images' === $this->file_type) { File::move($thumb_path . $old_name, $thumb_path . $new_name); } return 'OK'; }
/** * @return string */ public function getRename() { $old_name = Input::get('file'); $new_name = trim(Input::get('new_name')); $file_path = parent::getPath('directory'); $thumb_path = parent::getPath('thumb'); $old_file = $file_path . $old_name; if (!File::isDirectory($old_file)) { $extension = File::extension($old_file); $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension; } $new_file = $file_path . $new_name; if (Config::get('lfm.alphanumeric_directory') && preg_match('/[^\\w-]/i', $new_name)) { return Lang::get('laravel-filemanager::lfm.error-folder-alnum'); } elseif (File::exists($new_file)) { return Lang::get('laravel-filemanager::lfm.error-rename'); } if (File::isDirectory($old_file)) { File::move($old_file, $new_file); Event::fire(new FolderWasRenamed($old_file, $new_file)); return 'OK'; } File::move($old_file, $new_file); if ('Images' === $this->file_type) { File::move($thumb_path . $old_name, $thumb_path . $new_name); } Event::fire(new ImageWasRenamed($old_file, $new_file)); return 'OK'; }
protected function checkDirectory($namespace, $routePath) { $rootPath = config('routie.path'); $routePath = isset($namespace) ? $rootPath . '/' . $routePath : $rootPath; if (!File::isDirectory($routePath)) { File::makeDirectory($routePath, 0775, true); } return $routePath; }
private function registerNamespaces() { if (File::isDirectory(app_path() . '/config/packages/andywer/js-localization')) { Config::addNamespace('js-localization', app_path() . '/config/packages/andywer/js-localization'); } else { Config::addNamespace('js-localization', __DIR__ . '/../config'); } View::addNamespace('js-localization', __DIR__ . '/../views'); }
public function test_with_alpha3_lowercase_names() { $exitCode = Artisan::call('prep:country-flags', ['--name' => 2, '--case' => 'lower']); $this->assertEquals(0, $exitCode, 'Assert exit code is 0'); $this->assertTrue(File::isDirectory($this->dest), 'Assert flags directory was created'); $files = File::files($this->dest); $this->assertContains($this->dest . '/ukr.svg', $files, 'Assert img files were created with appropriate naming conventions'); $this->assertGreaterThan(200, count($files), 'Assert that count of generated flags is in expected range'); }
/** * Get the path where an image will be cached * * @param Image $image * * @return string */ public function getCachePathOf(Image $image) { $hash = $this->getHashOf($image); $cacheFolder = $this->illuminage->getCacheFolder(); $hashedFolder = $cacheFolder . $this->getHashedPath($hash); if ($hashedFolder and !File::isDirectory($hashedFolder)) { @File::makeDirectory($hashedFolder, 511, true); } return $hashedFolder . $hash; }
/** * Хэмжээтэй хавтаснуудыг үүсээгүй байвал үүсгэнэ. * * @return void */ private function createSizeFolder($size_name) { $p = $this->basePath . $size_name; if (!File::isDirectory($p)) { mkdir($p); } $p .= "/" . $this->folder; if (!File::isDirectory($p)) { mkdir($p); } }
/** * @param $path * @param $fileName * @return array */ public function findFiles($path, $fileName) { if ($path == '') { $path = base_path(); } if (File::isDirectory($path)) { $path = str_finish($path, '/'); } $path .= $fileName; return File::glob($path); }
/** * @param ImageUploader $uploader */ public function __construct(ImageUploader $uploader) { $this->uploader = $uploader; $this->uploadDirectory = public_path() . '/' . config('html_template_curator.upload_directory_name') . '/'; // Check if uploads folder exists and create if not if (!File::isDirectory($this->uploadDirectory)) { File::makeDirectory($this->uploadDirectory, 0755, true, true); } // Check if folder for storing images and temp dir exists and create if not if (!File::isDirectory($this->uploadDirectory . 'images/temp/')) { File::makeDirectory($this->uploadDirectory . 'images/temp/', 0755, true, true); } }
public function updateSpartan($account, $size = 512) { $spartan = $this->_getSpartanImage($account, $size); if ($spartan == null) { return; } $base = 'uploads/h5/'; // Create directory if (!File::isDirectory(public_path($base . $account->seo))) { File::makeDirectory(public_path($base . $account->seo), 0755, true); } $spartan->save(public_path($base . $account->seo . "/" . 'spartan.png')); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(CoursesRequest $request) { $course = Course::create($request->all()); $pathToCourse = storage_path() . '/courses/'; echo $pathToCourse; if (!File::isDirectory($pathToCourse)) { File::makeDirectory($pathToCourse); } File::makeDirectory($pathToCourse . $course->slug); $course->path_to_material = $pathToCourse . $course->slug; $course->save(); return redirect('courses'); }
private static function uploadToLocal($fileName, $file, $imagesdir) { $inputDir = Config::get('astroanu.imagecache.paths.input'); if (!File::isDirectory($inputDir)) { File::makeDirectory($inputDir); } $destDir = $inputDir . '/' . $imagesdir; if (!File::isDirectory($destDir)) { File::makeDirectory($destDir); } $image = $file->move($destDir, $fileName); return $fileName; }
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'); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle(Request $request, Closure $next) { $response = $next($request); // HTML cache if (!$response->isRedirection() && $request->isMethod('get') && !Auth::check() && !config('app.debug') && config('typicms.html_cache')) { if ($this->hasPageThatShouldNotBeCached($response)) { return $response; } $directory = public_path() . '/html' . $request->getPathInfo(); if (!File::isDirectory($directory)) { File::makeDirectory($directory, 0777, true); } File::put($directory . '/index' . ($request->getQueryString() ? md5($request->getQueryString()) : '') . '.html', $response->content()); } return $response; }
private function checkPathIsOk($path, $dir = null) { $path = rtrim($path, '/') . ($dir ? '/' . trim($dir, '/') : ''); if (File::isDirectory($path) && File::isWritable($path)) { return true; } else { try { @File::makeDirectory($path, 0777, true); return true; } catch (\Exception $e) { Log::error('Uploader: ' . $e->getMessage()); $this->results['error'] = $e->getMessage(); return false; } } }
/** * Delete image and associated thumbnail * * @return mixed */ public function getDelete() { $to_delete = Input::get('items'); $base = Input::get("base"); if ($base != "/") { if (File::isDirectory(base_path() . "/" . $this->file_location . $base . "/" . $to_delete)) { // make sure the directory is empty if (sizeof(File::files(base_path() . "/" . $this->file_location . $base . "/" . $to_delete)) == 0) { File::deleteDirectory(base_path() . "/" . $this->file_location . $base . "/" . $to_delete); return "OK"; } else { return "You cannot delete this folder because it is not empty!"; } } else { if (File::exists(base_path() . "/" . $this->file_location . $base . "/" . $to_delete)) { File::delete(base_path() . "/" . $this->file_location . $base . "/" . $to_delete); if (Session::get('lfm_type') == "Images") { File::delete(base_path() . "/" . $this->file_location . $base . "/" . "thumbs/" . $to_delete); } return "OK"; } else { return base_path() . "/" . $this->file_location . $base . "/" . $to_delete . " not found!"; } } } else { $file_name = base_path() . "/" . $this->file_location . $to_delete; if (File::isDirectory($file_name)) { // make sure the directory is empty if (sizeof(File::files($file_name)) == 0) { File::deleteDirectory($file_name); return "OK"; } else { return "You cannot delete this folder because it is not empty!"; } } else { if (File::exists($file_name)) { File::delete($file_name); if (Session::get('lfm_type') == "Images") { File::delete(base_path() . "/" . $this->file_location . "thumbs/" . $to_delete); } return "OK"; } else { return $file_name . " not found!"; } } } }
/** * Store a newly created resource in storage. * * @param SnippetsRequest|Request $request * @return \Illuminate\Http\Response */ public function store(SnippetsRequest $request) { //create snippet with all provided data $snippet = Snippet::create($request->all()); //create storage path $pathToSnippet = storage_path() . '/snippets/'; //add customer id to customer_snippet $snippet->customer()->attach($request->input('customer')); //create directory for snippet if (!File::isDirectory($pathToSnippet)) { File::makeDirectory($pathToSnippet); } File::makeDirectory($pathToSnippet . $snippet->slug); $snippet->path_to_material = $pathToSnippet . $snippet->slug; $snippet->save(); return redirect('snippets'); }
protected function bootRoutes() { $config = $this->app['config']; if ($config->has('routie.path')) { $root = $config->get('routie.path'); if (File::isDirectory($root)) { $path = str_replace('\\', '/', $root); $path = '/' . $path; $files = File::allFiles($path); foreach ($files as $file) { $filename = str_replace('/' . base_path() . '/', null, $file->getPathname()); $filename = ucfirst($filename); $filename = explode('.', $filename)[0]; $filename = str_replace('/', '\\', $filename); $this->app->make($filename); } } } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (config('typicms.auth_public') && !Auth::check()) { if (Request::ajax()) { return Response::make('Unauthorized', 401); } return Redirect::guest(route('login')); } $response = $next($request); // HTML cache if ($response instanceof View && $request->method() == 'GET' && !Auth::check() && $this->queryStringIsEmptyOrOnlyPage($request) && !config('app.debug') && config('typicms.html_cache')) { $directory = public_path() . '/html' . $request->getPathInfo(); if (!File::isDirectory($directory)) { File::makeDirectory($directory, 0777, true); } File::put($directory . '/index' . $request->getQueryString() . '.html', $response->render()); } return $response; }
/** * @return string */ public function getRename() { $file_to_rename = Input::get('file'); $dir = Input::get('dir'); $new_name = Str::slug(Input::get('new_name')); if ($dir == "/") { if (File::exists(base_path() . "/" . $this->file_location . $new_name)) { return "File name already in use!"; } else { if (File::isDirectory(base_path() . "/" . $this->file_location . $file_to_rename)) { File::move(base_path() . "/" . $this->file_location . $file_to_rename, base_path() . "/" . $this->file_location . $new_name); return "OK"; } else { $extension = File::extension(base_path() . "/" . $this->file_location . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; File::move(base_path() . "/" . $this->file_location . $file_to_rename, base_path() . "/" . $this->file_location . $new_name); if (Session::get('lfm_type') == "Images") { // rename thumbnail File::move(base_path() . "/" . $this->file_location . "thumbs/" . $file_to_rename, base_path() . "/" . $this->file_location . "thumbs/" . $new_name); } return "OK"; } } } else { if (File::exists(base_path() . "/" . $this->file_location . $dir . "/" . $new_name)) { return "File name already in use!"; } else { if (File::isDirectory(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename)) { File::move(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/" . $new_name); } else { $extension = File::extension(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; File::move(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/" . $new_name); if (Session::get('lfm_type') == "Images") { File::move(base_path() . "/" . $this->file_location . $dir . "/thumbs/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/thumbs/" . $new_name); } return "OK"; } } } return true; }
/** * Execute the console command. * * @return mixed */ public function handle() { $filePath = config('geolocator.path') . DIRECTORY_SEPARATOR . 'geolocator.zip'; try { $file = file_get_contents(config('geolocator.url'), false); if (!File::isDirectory(config('geolocator.path'))) { File::makeDirectory(config('geolocator.path')); } File::put($filePath, $file); } catch (Exception $e) { $this->error($e->getMessage()); return; } if ($this->extract($filePath)) { unlink($filePath); $this->info('Download and unzip success'); } else { $this->error('Error on unzip'); } }
public function boot() { $this->package('nem-c/ip2loc-lite'); $app = $this->app; //do we have config? $this->verifyConfig($app); $storagePath = $app['config']->get('ip2loc-lite::config.storagePath'); if (File::isDirectory($storagePath) === false) { File::makeDirectory($storagePath, 0777); File::put($storagePath . '/.gitignore', "*\n!.gitignore\n!cookies\n!downloads"); } if (File::isDirectory($storagePath . '/cookies') === false) { File::makeDirectory($storagePath . '/cookies', 0777); File::put($storagePath . '/cookies/.gitignore', "*\n!.gitignore"); } if (File::isDirectory($storagePath . '/downloads') === false) { File::makeDirectory($storagePath . '/downloads', 0777); File::put($storagePath . '/downloads/.gitignore', "*\n!.gitignore"); } }
protected function putFile($file_name, $file_contents) { $file = new \SplFileInfo($file_name); // if (File::exists($file_name)) { // $answer = $this->confirm($file->getFilename() . ' already exists, would you like to overwrite it?'); // if (!$answer) { // return false; // } // } if (!File::isDirectory($file->getPath())) { File::makeDirectory($file->getPath(), 0755, true); } try { file_put_contents($file_name, $file_contents); } catch (\ErrorException $e) { $this->error('File could not be saved'); die; } return true; }
public static function csv($name, array $data = [], array $structure = []) { $now = Carbon::now(); $dateString = $now->toDateString(); $path = static::getDirectory($name) . "/{$dateString}"; if (!File::isDirectory($path)) { File::makeDirectory($path, 0777, true); } $file = "{$path}/{$now->timestamp}.csv"; foreach ($data as &$record) { $copy = []; foreach ($structure as $field) { $copy[$field] = array_key_exists($field, $record) ? $record[$field] : ''; } $record = $copy; } $formatter = Formatter::make($data, Formatter::ARR); File::put($file, $formatter->toCsv()); return $file; }
/** * Resize the image * @return boolean */ private function resize() { $filename = $this->uploadObject->getAbsoluteSrc(); $extension = $this->uploadObject->extension; // Does the original file exist? If not return false if (!File::exists($filename)) { return false; } // Check to see our directory for caching exists, if it doesn't recursively create it if (!File::isDirectory($this->getPath())) { File::makeDirectory($this->getPath(), 0777, true); } $img = Image::make($filename); if ($this->crop) { $img->fit($this->width, $this->height)->save($this->getPathFilename()); } else { $img->resize($this->width, $this->height, true, true)->resizeCanvas($this->width, $this->height, null, false, 'ffffff')->save($this->getPathFilename()); } return true; }
/** * @return string */ function getRename() { $file_to_rename = Input::get('file'); $dir = Input::get('dir'); $new_name = Str::slug(Input::get('new_name')); if ($dir == "/") { if (File::exists(base_path() . "/" . Config::get('sfm.dir') . $new_name)) { return Lang::get('filemanager::sfm.file_exists'); } else { if (File::isDirectory(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename)) { File::move(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $new_name); return "OK"; } else { $extension = File::extension(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; if (@getimagesize(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename)) { // rename thumbnail File::move(base_path() . "/" . Config::get('sfm.dir') . "/.thumbs/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . "/.thumbs/" . $new_name); } File::move(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $new_name); return "OK"; } } } else { if (File::exists(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name)) { return Lang::get('filemanager::sfm.file_exists'); } else { if (File::isDirectory(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename)) { File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name); } else { $extension = File::extension(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename); $new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension; if (@getimagesize(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename)) { File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/.thumbs/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/.thumbs/" . $new_name); } File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name); return "OK"; } } } }
protected function generateFile($code) { if (!File::isDirectory($this->path)) { File::makeDirectory($this->path); } if (File::isWritable($this->path)) { if (!File::isDirectory($this->path . $this->pathfile)) { File::makeDirectory($this->path . $this->pathfile); } if (File::isWritable($this->path . $this->pathfile)) { File::put($this->filename, $code); if (File::exists($this->filename)) { return "File " . $this->filename . " created successfully"; } else { return "no se pudo crear " . $this->filename; } } return "No se puede escribir o no existe " . $this->path . $this->pathfile; } return "No se puede escribir o no existe " . $this->path; }
/** * Delete image and associated thumbnail * * @return mixed */ public function getDelete() { $to_delete = Input::get('items'); $base = Input::get("base"); if ($base != "/") { if (File::isDirectory(base_path() . "/" . Config::get('sfm.dir') . $to_delete)) { File::delete(base_path() . "/" . Config::get('sfm.dir') . $base . "/" . $to_delete); return "OK"; } else { if (File::exists(base_path() . "/" . Config::get('sfm.dir') . $base . "/" . $to_delete)) { if (@getimagesize(base_path() . "/" . Config::get('sfm.dir') . $base . "/" . $to_delete)) { File::delete(base_path() . "/" . Config::get('sfm.dir') . $base . "/.thumbs/" . $to_delete); } File::delete(base_path() . "/" . Config::get('sfm.dir') . $base . "/" . $to_delete); return "OK"; } else { return Lang::get('filemanager::sfm.not_found', ['file' => Config::get('sfm.dir') . $base . "/" . $to_delete]); } } } else { $file_name = base_path() . "/" . Config::get('sfm.dir') . $to_delete; if (File::isDirectory($file_name)) { // make sure the directory is empty if (sizeof(File::files($file_name)) == 0) { File::deleteDirectory($file_name); return "OK"; } else { return Lang::get('filemanager::sfm.not_empty'); } } else { if (File::exists($file_name)) { if (@getimagesize($file_name)) { File::delete(base_path() . "/" . Config::get('sfm.dir') . "/.thumbs/" . $to_delete); } File::delete($file_name); return "OK"; } } } }
/** * Delete image and associated thumbnail * * @return mixed */ public function getDelete() { $name_to_delete = Input::get('items'); $file_path = parent::getPath(); $file_to_delete = $file_path . $name_to_delete; $thumb_to_delete = parent::getPath('thumb') . $name_to_delete; if (!File::exists($file_to_delete)) { return $file_to_delete . ' not found!'; } if (File::isDirectory($file_to_delete)) { if (sizeof(File::files($file_to_delete)) != 0) { return Lang::get('laravel-filemanager::lfm.error-delete'); } File::deleteDirectory($file_to_delete); return 'OK'; } File::delete($file_to_delete); if (Session::get('lfm_type') == 'Images') { File::delete($thumb_to_delete); } return 'OK'; }
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); }