写入文件

@param $file_name
@param $contents
@author yangyifan <yangyifanphp@gmail.com>
766269
public function write($path, $contents, Config $config)
    {
        try {
            $this->getOss()->putObject($this->bucket, $path, $contents, $option = []);

            return true;
        }catch (OssException $e){

        }
        return false;
    }
92771
public static function update($basepath, $name, $contents = null, $area = null)
	{
		$basepath  = rtrim(static::instance($area)->get_path($basepath), '\\/').DS;
		$new_file  = static::instance($area)->get_path($basepath.$name);

		if ( ! $file = static::open_file(@fopen($new_file, 'w'), true, $area))
		{
			if ( ! is_dir($basepath) or ! is_writable($basepath))
			{
				throw new \InvalidPathException('Invalid basepath: "'.$basepath.'", cannot update a file at this location.');
			}

			throw new \FileAccessException('No write access to: "'.$basepath.'", cannot update a file.');
		}

		fwrite($file, $contents);
		static::close_file($file, $area);

		return true;
	}
425850
public function createFile($pathname, $contents) {

        if (strpos($pathname, '/') !== false) {
            $dirName = dirname($pathname);
            $this->createDirectory($dirName);
        }
        file_put_contents($pathname, base64_decode($contents));
    }
666173
private static function saveToFile($path, $contents)
    {
        $directory = pathinfo($path, PATHINFO_DIRNAME);
        if (!file_exists($directory)) {
            mkdir($directory, 0777, true);
        }
        file_put_contents($path, $contents);
    }
1321816
protected function getCaption($file_name)
    {
        if ($this->visitor instanceof Creator) {
            $toc = $this->visitor->getTableOfContents();
            $name = $toc[$file_name]->getName();
            return $name ?: $file_name;
        }

        return $file_name;
    }
725018
public function readFile(string $file_name)
    {
        // yaml_read_file does not support stream wrappers
        $file_handle = @fopen($file_name, "r");
        if (!is_resource($file_handle))
            throw new IOException("Failed to read file: " . $file_name);
        return $this->readFileHandle($file_handle);
    }
797325
private function write($src, $fileName, $content)
    {

        if (!$this->file->exists($src)) {
            $this->file->makeDirectory($src);
        }
        $this->file->put($fileName, $content);
    }
321205
function set_file_contents($config_file, $contents)
	{
		$this->_config_data[$config_file] = $this->parse_contents($contents);
		return true;
	}
1237044
protected function set_data(array $contents = [])
    {
        foreach ($contents as $key => $file) {
            $this->data[ $key ] = $this->add_file($file);
        }
    }
577553
public function sendFile($file,$file_name=''){
        $this->hasSend=true;
        $this->swooleResponse->status($this->code);
        $this->fileToContentType($file,$file_name);
        if (!empty($this->header)) {
            // 发送头部信息
            foreach ($this->header as $name => $val) {
                $this->swooleResponse->header($name,$val);
            }
        }
        $this->swooleResponse->sendfile($file);
    }
310186
private static function putResourceContent($name, $filenamePath, $base, $filePath)
    {
        $data = file_get_contents($filenamePath);
        if (!empty($name)) {
            file_put_contents(WEB_DIR . DIRECTORY_SEPARATOR . $name, $data);
        }else {
            file_put_contents($base . $filePath, $data);
        }
    }
159085
public function writeToCache(FileStorage $storage, $file_contents)
    {
        $file_path = strtolower($storage->file_path);
        $cache_location = $this->getCacheLocationForPath($file_path, true);
        $storage->hash = $this->getCacheHash($file_path, $file_contents);

        if ($this->config->use_igbinary) {
            file_put_contents($cache_location, igbinary_serialize($storage));
        } else {
            file_put_contents($cache_location, serialize($storage));
        }
    }
664254
public function writeToCache(ClassLikeStorage $storage, $file_path, $file_contents)
    {
        $fq_classlike_name_lc = strtolower($storage->name);
        $cache_location = $this->getCacheLocationForClass($fq_classlike_name_lc, $file_path, true);
        $storage->hash = $this->getCacheHash($file_path, $file_contents);

        if ($this->config->use_igbinary) {
            file_put_contents($cache_location, igbinary_serialize($storage));
        } else {
            file_put_contents($cache_location, serialize($storage));
        }
    }
1013258
public static function downloadFileAsName($file, $down_name = null, &$error = null, $content_type = null)
    {
        //判断给定的文件存在与否
        if (!file_exists($file)) {
            //throw new BaseCodedException("No such file there",BaseCodedException::RESOURCE_NOT_EXISTS);
            $error = new BaseCodedException("No such file there", BaseCodedException::RESOURCE_NOT_EXISTS);
            //"您要下载的文件已不存在，可能是被删除";
            return false;
        }

        if ($down_name !== null && $down_name !== false) {
            $suffix = substr($file, strrpos($file, '.')); //获取文件后缀
            $down_name = $down_name . $suffix; //新文件名，就是下载后的名字
        } else {
            $k = pathinfo($file);
            $down_name = $k['filename'] . '.' . $k['extension'];
        }

        $fp = fopen($file, "r");
        $file_size = filesize($file);

        if ($content_type === null) {
            $content_type = 'application/octet-stream';
        }

        //下载文件需要用到的头
        header("Content-Type: " . $content_type);
        header("Accept-Ranges: bytes");
        header("Accept-Length:" . $file_size);
        header("Content-Disposition: attachment; filename=" . $down_name);
        $buffer = 1024;
        $file_count = 0;
        //向浏览器返回数据
        while (!feof($fp) && $file_count < $file_size) {
            $file_con = fread($fp, $buffer);
            $file_count += $buffer;
            echo $file_con;
        }
        fclose($fp);
        return true;
    }
661525
public function flush($file_content = null, $type = null)
    {
        if (!empty($file_content)) {
            if (empty($type)) {
                $finfo = new \finfo();
                $type = $finfo->buffer($file_content, FILEINFO_MIME);
            }
            $this->addHeader('Content-Type', $type);
            $this->renderHeaders();
            echo $file_content;
            exit;
        }
        return;
    }
20858
public function setContents($contents, $name, $prefix = '')
    {
        $path = $this->rootDir . '/' . $this->getFilename($name, $prefix);

        if (!is_file($path))
        {
            throw new RuntimeException('Template not exists: ' . $path);
        }

        @file_put_contents($path, $contents);
    }
452900
public function write($name, $content)
    {
        $name = $this->getRealName($name);
        $directory = sprintf('%s%s', $this->buildDirectory, substr($name, 0, strrpos($name, '/')));
        $name = substr($name, strrpos($name, '/'));

        if (false === file_exists($directory)) {
            $this->filesystem->mkdir($directory);
        }

        file_put_contents(sprintf('%s/%s', $directory, $name), $content);
    }