/** * {@inheritdoc} */ public function readCss($uri) { $path = sprintf('%s/%s.css', $this->storage, urlencode($uri)); if (!$this->files->exists($path)) { return sprintf('/* Critical-path CSS for URI [%s] not found at [%s]. ' . 'Check the config and run `php artisan criticalcss:make`. */', $uri, $path); } return $this->files->get($path); }
/** * deletes all saved image data for given hash * * @param string $hash * @return mixed */ public function remove($hash) { $hash = $this->isHashValid($hash); foreach (array_keys(config('image-service.filters')) as $filterName) { $path = implode('/', [config('image-service.path'), $filterName, $hash]); if ($this->filesystem->exists($path)) { $this->filesystem->delete($path); } } }
/** * Upload a file. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\RedirectResponse */ public function addFile(Request $request) { $maxSize = $this->config->get('media.max_file_size', 3); $validator = $this->getValidationFactory()->make($request->all(), ['file' => 'required|mimes:' . $this->getAcceptedFiles() . '|max:' . $maxSize * 1024]); if ($validator->fails()) { return response($validator->getMessageBag()->get('file')[0], 500); } $filename = trim($request->file('file')->getClientOriginalName()); if ($this->storage->exists($request->input('current_directory') . '/' . $filename)) { return response($filename . " already exists.", 500); } $this->storage->put($request->input('current_directory') . '/' . $filename, file_get_contents($request->file('file'))); return redirect()->back(); }
protected function loadConfig(Filesystem $fs, $scraperDir) { $scraperConfigFile = $scraperDir . '/scraper.yml'; if (!$fs->exists($scraperConfigFile)) { return null; } $configString = $fs->get($scraperConfigFile); $parser = new Parser(); $config = $parser->parse($configString); if (!is_array($config) || !count($config) >= 2) { return null; } return $config; }
/** * @param Attachment $attachment * * @return bool */ private function exportAttachment(Attachment $attachment) : bool { $file = $attachment->fileName(); if ($this->uploadDisk->exists($file)) { try { $decrypted = Crypt::decrypt($this->uploadDisk->get($file)); $exportFile = $this->exportFileName($attachment); $this->exportDisk->put($exportFile, $decrypted); $this->getFiles()->push($exportFile); // explain: $this->explain($attachment); } catch (DecryptException $e) { Log::error('Catchable error: could not decrypt attachment #' . $attachment->id . ' because: ' . $e->getMessage()); } } return true; }
/** * Parse Filename * * @param UploadedFile $file Uploaded File * @param string $name String Name * @param string $folder String Folder * @param bool $override Boolean Over Ride * * @return bool|array */ protected function parseFile($file, $folder = null, $name = null, $override = false) { $folder = trim((string) $folder, '/'); $folder = $folder ? "{$folder}/" : ""; $this->storage->makeDirectory($folder); $name = $name ?: $file->getClientOriginalName(); $nameOriginal = str_slug(pathinfo($name, PATHINFO_FILENAME)); if (empty($nameOriginal)) { $nameOriginal = str_random(10); } $extension = $file->getClientOriginalExtension(); $size = $file->getClientSize(); $mime = $file->getClientMimeType(); $sufix = ''; $count = 1; do { $name = "{$nameOriginal}{$sufix}.{$extension}"; $filename = "{$folder}{$name}"; $sufix = "({$count})"; $count++; } while (!$override && $this->storage->exists($filename)); return compact('filename', 'name', 'extension', 'size', 'mime'); }
public function getBranchesToSync() { $allowedBranches = $this->setting('sync.sync.branches'); if (count($allowedBranches) === 0) { return []; } $branchesToSync = []; $branches = $this->github->repositories()->branches($this->setting('owner'), $this->setting('repository')); foreach ($branches as $branch) { $branchName = $branch['name']; if (!in_array('*', $allowedBranches, true) and !in_array($branchName, $allowedBranches, true)) { continue; } $sha = $branch['commit']['sha']; $cacheKey = md5($this->project->getName() . $branchName); $branch = $this->cache->get($cacheKey, false); $destinationPath = Path::join($this->project->getPath(), $branchName); if ($branch !== $sha or $branch === false or !$this->files->exists($destinationPath)) { $branchesToSync[] = $branchName; } } return $branchesToSync; }
/** * Check if set storage path is writable * @return void */ public function createDirectory($path) { if (!$this->storage->exists($path)) { $this->storage->makeDirectory($path, 0755, true); } }
/** * Ensure that directory exist * @param Filesystem $filesystem * @param string $path * @return void */ protected function ensureDirectoryExist(Filesystem $filesystem, $path) { // Remove file name from string to get directory $dir = implode('/', array_slice(explode('/', $path), 0, -1)); if (!$filesystem->exists($dir)) { $filesystem->makeDirectory($dir); } }
/** * @inheritdoc */ public function fileExists(File $file, array $options) { return $this->filesystem->exists($this->getFilePath($file, $options)); }
public function exists() : bool { return $this->disk->exists($this->path); }
/** * Remove old chunks. * * @param string $filePath * * @return void */ protected function removeOldData($filePath) { if ($this->storage->exists($filePath) && $this->storage->lastModified($filePath) < time() - $this->maxFileAge) { $this->storage->delete($filePath); } }
protected function ensureDirectory($path) { if (!$this->files->exists($path)) { $this->files->makeDirectory($path); } }
/** * Write the uploaded file to the local filesystem. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\JsonResponse */ public function handleUpload(Request $request) { $fineUploaderUuid = null; if ($request->has('qquuid')) { $fineUploaderUuid = $request->get('qquuid'); } //------------------------------ // Is it Post-processing? //------------------------------ if ($request->has('post-process') && $request->get('post-process') == 1) { # Combine chunks. $this->combineChunks($request); return collect(event(new Uploaded($fineUploaderUuid, $request)))->last(); // Return the result of the second event listener. } //---------------- // Prelim work. //---------------- if (!file_exists($this->temporaryChunksFolder) || !is_dir($this->temporaryChunksFolder)) { $this->filesystem->makeDirectory($this->temporaryChunksFolder); } # Temp folder writable? if (!is_writable($absolutePathToTemporaryChunksFolder = config('filesystems.disks.local.root') . $this->temporaryChunksFolder) || !is_executable($absolutePathToTemporaryChunksFolder)) { throw new FileStreamExceptions\TemporaryUploadFolderNotWritableException(); } # Cleanup chunks. if (1 === mt_rand(1, 1 / $this->chunksCleanupProbability)) { $this->cleanupChunks(); } # Check upload size against the size-limit, if any. if (!empty($this->sizeLimit)) { $uploadIsTooLarge = false; $request->has('qqtotalfilesize') && intval($request->get('qqtotalfilesize')) > $this->sizeLimit && ($uploadIsTooLarge = true); $this->filesizeFromHumanReadableToBytes(ini_get('post_max_size')) < $this->sizeLimit && ($uploadIsTooLarge = true); $this->filesizeFromHumanReadableToBytes(ini_get('upload_max_filesize')) < $this->sizeLimit && ($uploadIsTooLarge = true); if ($uploadIsTooLarge) { throw new FileStreamExceptions\UploadTooLargeException(); } } # Is there attempt for multiple file uploads? $collectionOfUploadedFiles = collect($request->file()); if ($collectionOfUploadedFiles->count() > 1) { throw new FileStreamExceptions\MultipleSimultaneousUploadsNotAllowedException(); } /** @var UploadedFile $file */ $file = $collectionOfUploadedFiles->first(); //-------------------- // Upload handling. //-------------------- if ($file->getSize() == 0) { throw new FileStreamExceptions\UploadIsEmptyException(); } $name = $file->getClientOriginalName(); if ($request->has('qqfilename')) { $name = $request->get('qqfilename'); } if (empty($name)) { throw new FileStreamExceptions\UploadFilenameIsEmptyException(); } $totalNumberOfChunks = $request->has('qqtotalparts') ? $request->get('qqtotalparts') : 1; if ($totalNumberOfChunks > 1) { $chunkIndex = intval($request->get('qqpartindex')); $targetFolder = $this->temporaryChunksFolder . DIRECTORY_SEPARATOR . $fineUploaderUuid; if (!$this->filesystem->exists($targetFolder)) { $this->filesystem->makeDirectory($targetFolder); } if (!$file->isValid()) { throw new FileStreamExceptions\UploadAttemptFailedException(); } $file->move(storage_path('app' . $targetFolder), $chunkIndex); return response()->json(['success' => true, 'uuid' => $fineUploaderUuid]); } else { if (!$file->isValid()) { throw new FileStreamExceptions\UploadAttemptFailedException(); } $file->move(storage_path('app'), $fineUploaderUuid); return collect(event(new Uploaded($fineUploaderUuid, $request)))->last(); // Return the result of the second event listener. } }
/** * Determine if a file exists. * * @param string $path * * @return bool */ public function exists($path) { $path = $this->getPathPrefix($path); return $this->drive->exists($path); }
/** * @param $fs Filesystem * @param $scrapers Collection **/ protected function processChunk(Filesystem $fs, Collection $scrapers) { $lastJob = 0; if ($fs->exists('lastScraperRun')) { $lastJob = $fs->get('lastScraperRun'); } $scrapers->slice($lastJob, self::JOBS_PER_CALL); $this->scheduleScrapers($scrapers); $nextJob = 0; if ($lastJob + self::JOBS_PER_CALL > $scrapers->count()) { $nextJob = $lastJob + self::JOBS_PER_CALL; } $fs->put('lastScraperRun', $nextJob); }
/** * Remove image from url * * @param $url */ public function remove($url) { if ($this->filesystem->exists($url)) { $this->filesystem->delete($url); } }