@param string      $path
@param string      $name
@param null|string $extension
@param int         $quality

@return bool
169033
public function save(string $path, string $name, ?string $extension = null, int $quality = 100): bool
    {
        if (false === is_dir($path)) {
            mkdir($path, 0777, true);
        }
        if (null === $extension) {
            /** @var string $extension */
            $extension = $this->extension;
        }
        if (true === $this->encrypted) {
            file_put_contents($path . $name . '.' . self::FORMAT_WD_IMAGE, $this->workingData);
            return true;
        } elseif (0 !== imagetypes()) {
            $filename = $path . $name . '.' . $extension;
            switch (strtolower($extension)) {
                case self::FORMAT_GIF:
                    imagegif($this->workingData, $filename);
                    break;
                case self::FORMAT_JPEG:
                case self::FORMAT_JPG:
                    imagejpeg($this->workingData, $filename, $quality);
                    break;
                case self::FORMAT_PNG:
                    imagepng($this->workingData, $filename, (int)round(9 - ((9 * $quality) / 100)));
                    break;
                default:
                    throw new ImageException('Unsupported file type');
            }
            return false;
        }
    }
150693
protected function validateFileType($name)
    {
        $extension = strtolower(File::extension($name));

        if (!in_array($extension, $this->assetExtensions)) {
            return false;
        }

        return true;
    }
401264
public function createPathHeader($name, $path = null)
    {
        $header = new Swift_Mime_Headers_PathHeader($name, $this->emailValidator);
        if (isset($path)) {
            $header->setFieldBodyModel($path);
        }
        $this->setHeaderCharset($header);

        return $header;
    }
1172045
public function create($name, $path, $table = null, $create = false)
    {
        $path = $this->getPath($name, $path);

        // First we will get the stub file for the migration, which serves as a type
        // of template for the migration. Once we have those we will populate the
        // various place-holders, save the file, and run the post create event.
        $stub = $this->getStub($table, $create);

        $this->files->put($path, $this->populateStub($name, $stub, $table));

        $this->firePostCreateHooks();

        return $path;
    }
747608
protected function _mkfile($path, $name) {
		if ($this->tmp) {
			$path = $path.'/'.$name;
			$local = $this->getTempFile();
			$res = touch($local) && ftp_put($this->connect, $path, $local, FTP_ASCII);
			@unlink($local);
			return $res ? $path : false;
		}
		return false;
	}
194767
public function name(?string $name = null, ?bool $extension = false)
  {
    if ($name !== null) {
      $this->info['name'] = $name . ($extension ? '.' . pathinfo($this->info['name'], PATHINFO_EXTENSION) : '');
      return $this;
    }

    return $this->info['name'];
  }
1186920
public function createFile($attribute, $path, $name)
    {
        $handlerCreateFile = $this->fileOption($attribute, 'createFile');
        $file = $handlerCreateFile($path, $name);
        if ($file) {
            $storage = $this->fileStorage($attribute);
            $contents = file_get_contents($path);
            $handlerTemplatePath = $this->fileOption($attribute, 'templatePath');
            if ($storage->write($handlerTemplatePath($file), $contents)) {
                $this->setState($attribute, $file);
                $this->owner->{$attribute} = $file->id;
                return $file;
            }
        } // @codeCoverageIgnore
        return false; // @codeCoverageIgnore
    }
1224323
public function cacheToJPEGFilename($quality, $backgroundColor, $pathinfo) {
		$folder = $this->owner->ParentID ? $this->owner->Parent()->Filename : ASSETS_DIR . "/";

		$format = $pathinfo['extension'].'tojpeg-'.$quality.'-'.$backgroundColor;

		if($this->owner instanceof SecureImage){
			return $folder . "_resampled/".md5($format."-".$pathinfo['filename']).".jpg";
		}else{
			return $folder . "_resampled/".$format."-".$pathinfo['filename'].".jpg";
		}
	}
81017
public function subtree($path, string &$name = null, bool $create = false): ?self
    {
        $parts = $this->split($path);

        $dirOrFile = array_shift($parts);
        if (!count($parts)) {
            $name = $dirOrFile;
            $subtree = $this;
        } else {
            $exists = isset($this->subTrees[$dirOrFile]);
            if (!$exists && !$create) {
                $subtree = null;
                $name = null;
            } else {
                if (!$exists && $create) {
                    $this->subTrees[$dirOrFile] = new self();
                }
                $subtree = $this->subTrees[$dirOrFile]->subtree($parts, $name, $create);
            }
        }

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

        $extension = pathinfo($imageTargetFilePath, PATHINFO_EXTENSION);

        switch ($extension) {
            case 'jpg':
            case 'jpeg':
                $resampleImageResource->setImageFormat('jpg');
                $resampleImageResource->setCompression(\Imagick::COMPRESSION_LOSSLESSJPEG);
                break;

            case 'gif':
                $resampleImageResource->setImageFormat('gif');
                $resampleImageResource->setCompression(\Imagick::COMPRESSION_UNDEFINED);
                break;

            case 'png':
                $resampleImageResource->setImageFormat('png');
                $resampleImageResource->setCompression(\Imagick::COMPRESSION_UNDEFINED);
                $resampleImageResource->setImageAlphaChannel(\Imagick::ALPHACHANNEL_ACTIVATE);
                $resampleImageResource->setBackgroundColor(new \ImagickPixel('transparent'));
                break;

            case 'webp':
                $resampleImageResource->setImageFormat('webp');
                $resampleImageResource->setCompression(\Imagick::COMPRESSION_UNDEFINED);
                $resampleImageResource->setImageAlphaChannel(\Imagick::ALPHACHANNEL_ACTIVATE);
                $resampleImageResource->setBackgroundColor(new \ImagickPixel('transparent'));
                break;
        }

        $resampleImageResource->setCompressionQuality($quality);
        $resampleImageResource->stripImage();

        return (bool)$resampleImageResource->writeImage($imageTargetFilePath);
    }
1310690
public function save($saveName, $quality = 80)
    {
        $type         = $this->getType(pathinfo($saveName, PATHINFO_EXTENSION));
        $imageFunc    = 'image' . $type;
        $errorMessage = 'Image saved is failed! Check the directory is can write?';

        if ($type === 'jpeg')
        {
            imageinterlace($this->newImage, true);

            if ( !$imageFunc($this->newImage, $saveName, $quality) )
            {
                throw new \ErrorException($errorMessage);
            }
        }
        else
        {
            if (!$imageFunc($this->newImage, $saveName))
            {
                throw new \ErrorException($errorMessage);
            }
        }

        $this->destroyAll();

        return $this;
    }
270098
public function saveImage($saveImageFilePath, $quality = null)
    {
        $quality = empty($quality) ? $this->config->offsetGet('quality') : $quality;
        $optimizerConfig = $this->config->offsetGet('optimizer');

        if ($this->driver->save($saveImageFilePath, $quality)) {
            if ($optimizerConfig === 'default') {
                $optimizer = new Optimizer();
                $optimizer->optimize($saveImageFilePath);
            } elseif ( ! empty($optimizerConfig[ 'factory' ])) {
                $factory = $optimizerConfig[ 'factory' ];
                $optimizer = new Optimizer();

                switch ($factory) {
                    case 'imageoptim';
                        $factory = new Imageoptim();
                        $factory->setUsername($optimizerConfig[ 'username' ]);
                        $optimizer->setImageFactory($factory);
                        break;
                }

                $optimizer->optimize($saveImageFilePath);
            }

            return true;
        }

        return false;
    }
735332
protected function _mkfile($path, $name) {
		$path = $path.DIRECTORY_SEPARATOR.$name;
		
		if (($fp = @fopen($path, 'w'))) {
			@fclose($fp);
			@chmod($path, $this->options['fileMode']);
			return $path;
		}
		return false;
	}
1207065
public function is_extension($name, $value, $extensions){
        if(! $this->not_empty($name, $value)){
            return TRUE;
        }
        $extensions= explode(',', $extensions);
        $ok= TRUE;
        if($this->isMultiple($value)){
            foreach ($value['name'] as $name) {
                $ext = pathinfo($name, PATHINFO_EXTENSION);
                if (in_array($ext, $extensions)){
                    $ok= FALSE;
                    break;
                }
            }
        }else{
            $ext = pathinfo($value['name'], PATHINFO_EXTENSION);
            $ok= (in_array($ext, $extensions));
        }        
        
        if($ok){
            return TRUE;
        }else{
            $this->add_message($name, 'is_extension', array('extensions' => $extensions));
            return FALSE;
        }
    }
1004861
public function extension(string $name): bool
    {
        if (\is_null($path = $this->getPathFromExtensionName($name))) {
            return false;
        }

        try {
            return $this->publish($name, $path);
        } catch (Exception $e) {
            throw new FilePermissionException("Unable to publish [{$path}].");
        }
    }
1008614
protected function _mkdir($path, $name) {
		$path = $this->_normpath($path.'/'.$name);
		try {
			$this->dropbox->createFolder($path);
		} catch (Dropbox_Exception $e) {
			$this->deltaCheck();
			if ($this->dir($this->encode($path))) {
				return $path;
			}
			return $this->setError('Dropbox error: '.$e->getMessage());
		}
		$this->deltaCheck();
		return $path;
	}
123527
protected function mimetype($path, $name = '') {
		$type = '';
		
		if ($this->mimeDetect == 'finfo') {
			if ($type = @finfo_file($this->finfo, $path)) {
				if ($name === '') {
					$name = $path;
				}
				$ext = (false === $pos = strrpos($name, '.')) ? '' : substr($name, $pos + 1);
				if ($ext && preg_match('~^application/(?:octet-stream|(?:x-)?zip)~', $type)) {
					if (isset(elFinderVolumeDriver::$mimetypes[$ext])) $type = elFinderVolumeDriver::$mimetypes[$ext];
				}
			}
		} elseif ($type == 'mime_content_type') {
			$type = mime_content_type($path);
		} else {
			$type = elFinderVolumeDriver::mimetypeInternalDetect($path);
		}
		
		$type = explode(';', $type);
		$type = trim($type[0]);

		if (in_array($type, array('application/x-empty', 'inode/x-empty'))) {
			// finfo return this mime for empty files
			$type = 'text/plain';
		} elseif ($type == 'application/x-zip') {
			// http://elrte.org/redmine/issues/163
			$type = 'application/zip';
		}
		
		return $type == 'unknown' && $this->mimeDetect != 'internal'
			? elFinderVolumeDriver::mimetypeInternalDetect($path)
			: $type;
		
	}