保存指定文件
@param  array   $file    保存的文件信息
@param  boolean $replace 同名文件是否覆盖
@return boolean          保存状态，true-成功，false-失败
357132
public function save(&$file, $replace=true) {
        $filename = ltrim($this->rootPath .'/'. $file['savepath'] . $file['savename'],'/');
        $st =   new \SaeStorage();
        /* 不覆盖同名文件 */ 
        if (!$replace && $st->fileExists($this->domain,$filename)) {
            $this->error = '存在同名文件' . $file['savename'];
            return false;
        }

        /* 移动文件 */
        if (!$st->upload($this->domain,$filename,$file['tmp_name'])) {
            $this->error = '文件上传保存错误！['.$st->errno().']:'.$st->errmsg();
            return false;
        }else{
            $file['url'] = $st->getUrl($this->domain, $filename);
        }
        return true;
    }
664252
protected function fileMime($file, $rule)
    {
        if (!($file instanceof File)) {
            return false;
        }
        if (is_string($rule)) {
            $rule=explode(',', $rule);
        }
        if (is_array($file)) {
            foreach ($file as $item) {
                if (!$item->checkMime($rule)) {
                    return false;
                }
            }
            return true;
        } else {
            return $file->checkMime($rule);
        }
    }
353402
public function save($data, $replace = true)
    {
        if ($data instanceof Model) {
            $data = $data->getData();
        }

        // 保存关联表数据
        $data[$this->foreignKey] = $this->parent->{$this->localKey};

        $model = new $this->model;

        return $model->replace($replace)->save($data) ? $model : false;
    }
943002
public function insertAll(array $dataSet, $replace = false)
    {
        // 分析查询表达式
        $options = $this->parseExpress();
        if (!is_array(reset($dataSet))) {
            return false;
        }
        // 生成SQL语句
        $sql = $this->builder->insertAll($dataSet, $options, $replace);
        // 获取参数绑定
        $bind = $this->getBind();
        if ($options['fetch_sql']) {
            // 获取实际执行的SQL语句
            return $this->connection->getRealSql($sql, $bind);
        } else {
            // 执行操作
            return $this->execute($sql, $bind);
        }
    }
78677
public function rename(string $newName, bool $replace = true): bool
    {
        //根据是否覆盖
        $ret = $replace ? $this->handle->rename($this->name, $newName) : $this->handle->renameNx($this->name, $newName);

        //如果改名成功,修改本对象的键
        if ($ret) {
            $this->name = $newName;
        }
        return $ret;
    }
146150
protected function replace($search, $replace, $path)
    {
        file_put_contents($path, str_replace($search, $replace, file_get_contents($path)));
    }
609863
public static function saveAs($file, $options = [])
    {
        if (!($file instanceof UploadedFile)) {
            $file = UploadedFile::getInstanceByName($file);
        }
        $options['file'] = $file;
        $model = new static($options);
        return $model->save() ? $model : false;
    }
607129
public function rm(string $directory): bool {
    if (is_dir($directory)) {
      foreach (new DirectoryIterator(Path::replaceOSSeparator($directory)) as $fileInfo) {
        if (!$fileInfo->isDot()) {
          if ($fileInfo->isDir()) {
            $this->rm($fileInfo->getPathname());
            @rmdir($fileInfo->getPathname());
          } else if ($fileInfo->isFile()) {
            @unlink($fileInfo->getPathname());
          }
        }
      }
      @rmdir($directory);
    }
    return !file_exists($directory);
  }
228146
public function setStubUsingFile($file, $replace = false)
    {
        if (false === is_file($file)) {
            throw FileException::create(
                'The file "%s" does not exist or is not a file.',
                $file
            );
        }

        if (false === ($contents = @file_get_contents($file))) {
            throw FileException::lastError();
        }

        if ($replace) {
            $contents = $this->replaceValues($contents);
        }

        $this->phar->setStub($contents);
    }
264239
public static function writeFile($file, $content) {
		if (!@is_file($file)) {
			$changePermissions = TRUE;
		}

		if ($fd = fopen($file, 'wb')) {
			$res = fwrite($fd, $content);
			fclose($fd);

			if ($res === FALSE) {
				return FALSE;
			}

			if ($changePermissions) { // Change the permissions only if the file has just been created
				self::fixPermissions($file);
			}

			return TRUE;
		}

		return FALSE;
	}
1124969
public function save(string $field, array $file) : ?FileStorage
    {
        $required = ['tmp_name', 'error', 'name', 'type', 'size'];

        $diff = array_diff($required, array_keys($file));
        if (! empty($diff)) {
            $this->log(sprintf('Missing the following required parameter(s): %s', implode(',', $diff)), 'error');

            return null;
        }

        if (0 !== $file['error']) {
            $this->log(sprintf('File upload error code: %s', $file['error']), 'error');

            return null;
        }

        $entity = $this->storageTable->newEntity(['file' => $file]);
        Assert::isInstanceOf($entity, FileStorage::class);

        /**
         * Field foreign_key is not set here because upload does not know
         * anything about the entity it relates to, as it is not yet created.
         *
         * @var \Burzum\FileStorage\Model\Entity\FileStorage
         */
        $entity = $this->storageTable->patchEntity($entity, [
            'model' => $this->table->getTable(),
            'model_field' => $field
        ]);

        // always store extension in lowercased format
        $entity->set('extension', strtolower($entity->get('extension')));

        if (! $this->storageTable->save($entity)) {
            $this->log(sprintf('Failed to save file with name: %s', $file['name']), 'error');

            return null;
        }

        // generate thumbnails for image files
        if (in_array(strtolower($entity->get('extension')), self::IMAGE_EXTENSIONS)) {
            $this->createThumbnails($entity);
        }

        return $entity;
    }
982225
public static function clear($file = false) {

        if ($file && self::isFile($file)) {

            $f = @fopen($file, "r+");
            if ($f !== false) {
                ftruncate($f, 0);
                fclose($f);

                return true;
            }
        }

        return false;
    }
610293
public static function cleanFilename($filename,$replacement='-'){
		$filename = str_replace("\0",'',$filename);
		$filename = preg_replace('#[^a-zA-Z0-9._-]+#',$replacement,$filename);
		if(strlen($filename)>255){
			$ext = substr($filename,strrpos($filename,'.'));
			$name = substr($filename,0,255-strlen($ext));
			$filename = $name.$ext;
		}
		return $filename;
	}
787633
public static function replace(String $file, $data, $replace) : String
    {
        $file = Info::rpath($file);

        if( ! is_file($file))
        {
            return false;
        }

        return Filesystem::replaceData($file, $data, $replace);
    }
1137901
function fillDirName($user, $file)
    {
        //发过来的文件名不带路径需要补齐
        if (substr($file, 0, 1) != "/")
        {
            $file = $this->getUserDir($user) . "/" . $file;
        }
        if ($this->users[$user]['chroot'])
        {
            $file = $this->users[$user]['home'].$file;
        }
        return $file;
    }
512604
public static function makeSafe($file, array $stripChars = array('#^\.#'))
	{
		$regex = array_merge(array('#(\.){2,}#', '#[^A-Za-z0-9\.\_\- ]#'), $stripChars);

		$file = preg_replace($regex, '', $file);

		// Remove any trailing dots, as those aren't ever valid file names.
		$file = rtrim($file, '.');

		return $file;
	}
685771
public function save($file, $replace = true) {
        $header['Content-Type'] = $file['type'];
        $header['Content-MD5'] 	= $file['md5'];
        $header['Mkdir'] = 'true';
        $resource = fopen($file['tmp_name'], 'r');

        $save = $this->rootPath . $file['savepath'] . $file['savename'];
        $data = $this->request($save, 'PUT', $header, $resource);
        return false === $data ? false : true;
    }