/**
  * Validate that the storage directory exists. If it does not, create it.
  *
  * @return bool
  */
 public function validateStoragePath()
 {
     if (!$this->files->exists($this->storage)) {
         return $this->files->makeDirectory($this->storage);
     }
     return true;
 }
Exemple #2
0
 /**
  * Get chuck upload path.
  * 
  * @return string
  */
 public function getChunkPath()
 {
     $path = $this->app['config']->get('plupload.chunk_path');
     if (!$this->storage->isDirectory($path)) {
         $this->storage->makeDirectory($path, 0777, true);
     }
     return $path;
 }
 /**
  * Return the directory where all files of the given media are stored.
  *
  * @param \Spatie\MediaLibrary\Media $media
  *
  * @return string
  */
 public function getMediaDirectory(Media $media)
 {
     $this->disk->put('.gitignore', Gitignore::getContents());
     $directory = $media->id;
     $this->disk->makeDirectory($directory);
     $this->disk->makeDirectory($directory . '/conversions');
     return $directory;
 }
 /**
  * create filtered image
  *
  * @param string $hash
  * @param string $filename
  * @param string[]|string $filters
  * @return void
  */
 public function create($hash, $filename, $filters)
 {
     $filteredImages = [];
     $imageContent = $this->filesystem->get(config('image-service.path') . '/original/' . $hash . '/' . $filename);
     $image = $this->imageManager->make($imageContent);
     // if just one filter as string
     if (is_string($filters)) {
         $filters = [$filters];
     }
     foreach ($filters as $filterName) {
         $filterData = config('image-service.filters.' . $filterName);
         /** @var Filter $filter */
         $filter = app('image.filters.' . $filterData['type']);
         $filteredImage = $filter->process($image, isset($filterData['options']) ? $filterData['options'] : []);
         // cache if needed
         if (isset($filterData['cache']) && $filterData['cache'] === true) {
             $filterPath = config('image-service.path') . '/' . $filterName . '/' . $hash;
             $this->filesystem->makeDirectory($filterPath);
             $this->filesystem->put($filterPath . '/' . $filename, $filteredImage->encode(null, 100));
         }
         // save to return it
         $filteredImages[$filterName] = $filteredImage;
     }
     return $filteredImages;
 }
 /**
  * @param Filesystem $filesystem
  * @return CommandResult
  */
 public function handle(Filesystem $filesystem)
 {
     // check if user has permission
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission(['media.manage'])) {
             return new CommandResult(false, "Not enough permission.", null, 403);
         }
     }
     $path = is_null($this->path) ? '/' : $this->path;
     if (!($dir = $filesystem->makeDirectory($this->normalizePath($path) . $this->dirName))) {
         return new CommandResult(false, "Failed to create directory.", null, 400);
     }
     // all good
     return new CommandResult(true, "Make directory command successful.", array($dir), 201);
 }
Exemple #6
0
 /**
  * Create a folder.
  *
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function addFolder(Request $request)
 {
     // check if public/media is the parent folder
     if (strpos($request->input('current_directory'), $this->getRootDir()) === false) {
         flash()->error('Invalid folder!');
         return redirect()->back();
     }
     // check if alphanumeric and no space
     if (!ctype_alnum($request->input('new_directory'))) {
         flash()->error('Invalid folder name! Folder name must be alphanumeric only and no space');
         return redirect()->back();
     }
     $this->storage->makeDirectory($request->input('current_directory') . '/' . $request->input('new_directory'));
     // new current directory
     $folder = $request->input('current_directory') . '/' . $request->input('new_directory');
     flash()->success('New Folder added successfully!');
     return redirect()->back()->with('folder', $folder);
 }
 /**
  * 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');
 }
 /**
  * Copy the given file on the given disk to the given destination.
  *
  * @param string                                      $file
  * @param \Illuminate\Contracts\Filesystem\Filesystem $disk
  * @param string                                      $destination
  * @param bool                                        $addIgnoreFile
  */
 protected function copyFile($file, $disk, $destination, $addIgnoreFile = false)
 {
     $destinationDirectory = dirname($destination);
     $disk->makeDirectory($destinationDirectory);
     if ($addIgnoreFile) {
         $this->writeIgnoreFile($disk, $destinationDirectory);
     }
     /*
      * The file could be quite large. Use a stream to copy it
      * to the target disk to avoid memory problems
      */
     $disk->getDriver()->writeStream($destination, fopen($file, 'r+'));
 }
Exemple #9
0
 /**
  * Create a directory.
  *
  * @param  string $path
  *
  * @return bool
  */
 public function makeDirectory($path)
 {
     $path = $this->getPathPrefix($path);
     return $this->drive->makeDirectory($path);
 }
 /**
  * Check if set storage path is writable
  * @return void
  */
 public function createDirectory($path)
 {
     if (!$this->storage->exists($path)) {
         $this->storage->makeDirectory($path, 0755, true);
     }
 }
Exemple #11
0
 /**
  * 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);
     }
 }
Exemple #12
0
 public function syncRef($ref, $type)
 {
     $content = new GitSyncContent($this->setting('owner'), $this->setting('repository'), $this->github);
     $hasDocs = $content->exists($this->setting('sync.paths.docs'), $ref);
     if (!$hasDocs) {
         return;
     }
     $destinationDir = Path::join($this->project->getPath(), $ref);
     $menu = $content->show($this->setting('sync.paths.menu'), $ref);
     $menuContent = base64_decode($menu['content']);
     $menuArray = Yaml::parse($menuContent);
     $unfilteredPages = [];
     $this->extractDocumentsFromMenu($menuArray['menu'], $unfilteredPages);
     $filteredPages = [];
     # filter out pages that link to external sites
     foreach ($unfilteredPages as $page) {
         if (Str::startsWith($page, 'http', true) || Str::startsWith($page, '//', true) || Str::startsWith($page, 'git', true)) {
             continue;
         }
         if (!in_array($page, $filteredPages, true)) {
             $filteredPages[] = $page;
         }
     }
     # get all pages their content and save to local
     foreach ($filteredPages as $pagePath) {
         $path = Path::join($this->setting('sync.paths.docs'), $pagePath . '.md');
         # check if page exists on remote
         $exists = $content->exists($path, $ref);
         if (!$exists) {
             continue;
         }
         # the raw github page content response
         $pageRaw = $content->show('/' . $path, $ref);
         # transform remote directory path to local directory path
         $dir = Str::remove($pageRaw['path'], $this->setting('sync.paths.docs'));
         $dir = Str::remove($dir, $pageRaw['name']);
         $dir = Path::canonicalize(Path::join($destinationDir, $dir));
         if (!$this->files->exists($dir)) {
             $this->files->makeDirectory($dir);
         }
         # raw github page to utf8 and save it to local
         $this->files->put(Path::join($dir, $pageRaw['name']), base64_decode($pageRaw['content']));
     }
     # save the menu to local
     $this->files->put(Path::join($destinationDir, 'menu.yml'), $menuContent);
     # if enabled, Get phpdoc structure and save it
     if ($this->setting('phpdoc')) {
         $hasStructure = $content->exists($this->setting('paths.phpdoc'), $ref);
         if ($hasStructure) {
             $structure = $content->show($this->setting('paths.phpdoc'), $ref);
             $structureXml = base64_decode($structure['content']);
             $destination = Path::join($destinationDir, 'structure.xml');
             $destinationDir = Path::getDirectory($destination);
             if (!$this->files->exists($destinationDir)) {
                 $this->files->makeDirectory($destinationDir);
             }
             $this->files->put($destination, $structureXml);
         }
     }
     # set cache sha for branches, not for tags (obviously)
     if ($type === 'branch') {
         $branchData = $this->github->repositories()->branches($this->setting('owner'), $this->setting('repository'), $ref);
         $this->cache->forever(md5($this->project->getName() . $branchData['name']), $branchData['commit']['sha']);
     }
 }
Exemple #13
0
 protected function ensureDirectory($path)
 {
     if (!$this->files->exists($path)) {
         $this->files->makeDirectory($path);
     }
 }
Exemple #14
0
 /**
  * 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.
     }
 }
 /**
  * Creates directory if it does not exists
  *
  * @param $directory
  * @return bool
  */
 protected function ensureDirectoryExistence($directory)
 {
     return $this->filesystem->makeDirectory($directory);
 }