Creates a backup of a media file
@param  string $originalPath The original file path
@return [type]               [description]
12241
public function createBackup($originalPath)
    {
        // Bail if file does not exist
        if (!file_exists($originalPath)) {
            return false;
        }

        $pathinfo = pathinfo($originalPath);

        $backupPrefered = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '.' . $pathinfo['extension'] . '.bkp';
        $backupFile = $backupPrefered;

        $i = 0;
        while (file_exists($backupFile)) {
            $i++;
            $backupFile = $backupPrefered . $i;
        }

        if (copy($originalPath, $backupFile)) {
            return $backupFile;
        }

        return false;
    }
591629
public function createFromNonExistantPath(string $path): File
    {
        $file = new File($path);
        if (true === $file->exists()) {
            throw new DoctrineStaticMetaException('File exists at ' . $path);
        }

        return $file;
    }
1289465
public function copyTo(string $fullPath) : IFile
    {
        if ($this->copyCallback) {
            return call_user_func($this->copyCallback, $fullPath);
        }

        return $this->file;
    }
1073268
public function loadFromFile($additionalPath = '')
    {
        $path = $this->testPath($this->realPath($additionalPath));
        
        if ($path === false) {
            return '';
        }
        
        return file_get_contents($path);
    }
248131
protected function createBackupFile($original, $backup)
    {
        $isOk = !file_exists($original) || rename($original, $backup);

        return $isOk;
    }
1169292
protected function getRecordForFile($path, $existing_media)
    {
        $directory = File::cleanDirname($path);
        $filename = pathinfo($path, PATHINFO_FILENAME);
        $extension = pathinfo($path, PATHINFO_EXTENSION);

        return $existing_media->filter(function (Media $media) use ($directory, $filename, $extension) {
            return $media->directory == $directory && $media->filename == $filename && $media->extension == $extension;
        })->first();
    }
49365
public static function createFromPath(string $path)
    {
        $createFunctions = [
            'image/png' => 'imagecreatefrompng',
            'image/jpeg' => 'imagecreatefromjpeg',
            'image/gif' => 'imagecreatefromgif',
        ];

        $mimeType = mime_content_type($path);

        if (!array_key_exists($mimeType, $createFunctions)) {
            throw new InvalidMimeTypeException(sprintf('The "%s" mime type is not supported.', $mimeType));
        }

        $resource = $createFunctions[$mimeType]($path);

        return new static($resource);
    }
1202564
public function getFile($path) {
		$dirPath = realpath($this->path);
		
		if ($dirPath === false) {
			throw new InvalidPath('Path "' . $this->path . '" doesn\'t exists or inaccsessible', null, null, $this->path);
		}
		
		return new File($dirPath . DIRECTORY_SEPARATOR . $path);
	}
448610
public function getFile(FilePath $path)
    {
        $absolutePath = $this->gitService->getAbsolutePath($path);

        return new File($absolutePath->toAbsoluteString(DIRECTORY_SEPARATOR));
    }
611836
public function create( $Path, $expire = 0, $fullUrl = ''){
        $Path_b64   = base64_encode( $Path);
        $expire     = $expire ?: (time() + (60*60*24)); // If expire is not defined, default is 24h
        $rest = $this->getService( self::API_SHARE_LINK);
        $rest->POST([
            'path'      => $Path_b64,
            'expire'    => $expire,
            'fullurl'   => $fullUrl,
        ]);

        return $rest->getResult( models\FileSystem\ShareLink::class);
    }
659255
public function cropImage($original, $path, $width, $height)
    {
        $original = $this->getFullPath($original);

        // Create folder if it doesn't exist
        $pathArray = explode('/', $path);
        array_pop($pathArray);
        $folder = implode('/', $pathArray);
        if (! file_exists($folder)) {
            mkdir($folder, 0777, true);
        }

        $file = \File::get($original);

        $img = \Image::make($file)->crop($width, $height);

        $img->save($path);

        return $this->showFile($path);
    }
7634
public function save($imageTargetFilePath, $quality = 100)
    {
        $resampleImageResource =& $this->getResampleImageResource();

        $extension = pathinfo($imageTargetFilePath, PATHINFO_EXTENSION);

        switch ($extension) {
            case 'jpg':
            case 'jpeg':
                return (bool)@imagejpeg($resampleImageResource, $imageTargetFilePath, $quality);
                break;

            case 'gif':
                return (bool)@imagegif($resampleImageResource, $imageTargetFilePath);
                break;

            case 'png':
                imagealphablending($resampleImageResource, false);
                imagesavealpha($resampleImageResource, true);

                return (bool)@imagepng($resampleImageResource, $imageTargetFilePath);
                break;

            case 'webp':
                return (bool)@imagewebp($resampleImageResource, $imageTargetFilePath);
                break;
        }

        return false;
    }
974464
public function withBasePath($basePath)
    {
        if (!is_string($basePath)) {
            throw new InvalidArgumentException('Uri path must be a string');
        }
        if (!empty($basePath)) {
            $basePath = '/' . trim($basePath, '/');
        }
        $clone = clone $this;

        if ($basePath !== '/') {
            $clone->basePath = Validator::checkPath($basePath);
        }

        return $clone;
    }
139359
protected function backupFile($filePath)
    {
        $sourcePath = $filePath;
        $backupPath = $filePath.'.bak';

        if (file_exists($backupPath)) {
            $date = new \DateTime();
            $backupPath = "{$filePath}{$date->getTimestamp()}.bak";
        }

        copy($sourcePath, $backupPath);

        return $backupPath;
    }
593317
public function moveFolder($originalPath, $newPath)
    {
        if (Str::lower($originalPath) !== Str::lower($newPath)) {
            // If there is no risk that the directory was renamed
            // by just changing the letter case in the name -
            // copy the directory to the destination path and delete
            // the source directory.

            if (!$this->copyFolder($originalPath, $newPath)) {
                return false;
            }

            $this->deleteFolder($originalPath);
        }
        else {
            // If there's a risk that the directory name was updated
            // by changing the letter case - swap source and destination
            // using a temporary directory with random name.

            $tempraryDirPath = $this->generateRandomTmpFolderName(dirname($originalPath));

            if (!$this->copyFolder($originalPath, $tempraryDirPath)) {
                $this->deleteFolder($tempraryDirPath);

                return false;
            }

            $this->deleteFolder($originalPath);

            return $this->moveFolder($tempraryDirPath, $newPath);
        }

        return true;
    }
1353036
public function create($path, $expire = 0, $fullUrl = '')
    {
        $Path_b64 = base64_encode($path);
        $expire   = $expire ?: (time() + (60 * 60 * 24)); // If expire is not defined, default is 24h
        $result     = $this->callService('POST', self::API_SHARE_LINK, [
            'path'    => $Path_b64,
            'expire'  => $expire,
            'fullurl' => $fullUrl,
        ]);

        return $result->getModel(models\FileSystem\ShareLink::class);
    }
1002590
protected function newPath(/*# string */ $path)/*# : Path */
    {
        list($mnt, $remain) = $this->splitPath($path);
        return new Path($path, $remain, $this->getFilesystemAt($mnt));
    }