文件写操作.


@param string $file_name 文件路径
@param string $content   文件内容

@return bool
194521
public function write($file_name, $content = '')
    {
        if (!is_file($file_name)) {
            return false;
        }

        return file_put_contents($file_name, $content, LOCK_EX);
    }
208644
protected function isValidFileOrUrl($name, $contents)
    {
        //Don't try to open a url as an actual file when using this method to setWebhook.
        if ($name == 'url') {
            return false;
        }

        //If a certificate name is passed, we must check for the file existing on the local server,
        // otherwise telegram ignores the fact it wasn't sent and no error is thrown.
        if ($name == 'certificate') {
            return true;
        }

        //Is the content a valid file name.
        if (is_readable($contents)) {
            return true;
        }

        //Is the content a valid URL
        return filter_var($contents, FILTER_VALIDATE_URL);
    }
1338156
private function setContent($name, $content)
    {
        $filename = $this->getCacheFileName($name);

        if ($this->options['thread_safe']) {
            $fd = fopen($filename, 'w+');
            flock($fd, LOCK_EX);
            $fr = fwrite($fd, $content);
            fclose($fd);

            return $fr;
        } else {
            return file_put_contents($filename, $content);
        }
    }
653775
public function forbids($file_name, $case_sensitive = false)
    {
        if ($this->inclusive && $this->file_filter) {
            if (!$this->file_filter->allows($file_name, $case_sensitive)) {
                return true;
            }
        }

        return false;
    }
1035903
public function __contruct($file_name = '')
    {

        if (empty($file_name)) return;

        $this->open($file_name);

        $this->imagemagik = new \Imagick($file_name);
    }
1014611
public function contains($content, $name)
    {
        if ($this->exists($name)) {
            preg_match_all('/'.$this->getRegex().'/s', $content, $matches, PREG_SET_ORDER);

            if (empty($matches)) {
                return false;
            }

            foreach ($matches as $shortcode) {
                if ($name === $shortcode[2]) {
                    return true;
                }
            }
        }

        return false;
    }
978022
public static function getFileNameSave($file_name)
    {
        FileHelper::createDirectory(self::getUploadDir() . '/' . date('Y/m/d'));
        return self::getUploadDir() . '/' . $file_name;
    }
1022492
protected function getFilename($name, $type, $index, $content_range, $tmp_name)
    {
        $name = $this->trimFilename($name, $type, $index, $content_range);

        return ($this->fileNameGenerator->getFileName($name, $type, $tmp_name, $index, $content_range, $this));
    }
568093
protected function putIntoFile($file_path, $data)
    {
        if ($this->files->isDirectory($this->files->dirname($file_path))) {
            $data = str_replace(["\n", "\r"], '', trim((string) $data));

            return $this->files->put($file_path, $data, $this->use_locking) > 0;
        }

        // @codeCoverageIgnoreStart
        return false;
        // @codeCoverageIgnoreEnd
    }
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;
    }
785129
public function input($filename, $content)
    {
        $this->_currentFile = $filename;
        return preg_replace_callback(
            $this->_pattern,
            array($this, '_replace'),
            $content
        );
    }
254938
public function write_cache($cache_path, $content)
    {
        $cache_content = json_encode($content);
        $cache_size = strlen($cache_content);

        $temp = tempnam($this->params['path'], 'temp');
        if (!($f = @fopen($temp, 'wb'))) { 
            $temp = $this->params['path'].'/'.uniqid('temp'); 
            if (!($f = @fopen($temp, 'wb'))) { 
                throw new WriteException('Unable to write temporary file '.$temp);
            }
        }

        fwrite($f, $cache_content); 
        fclose($f); 

        if (!rename($temp, $cache_path)) { 
            unlink($cache_path); 
            rename($temp, $cache_path); 
        } 

        chmod($cache_path, $this->params['write_perms']); 

        return $cache_size;
    }
269738
public function input($file_content)
    {
        $this->file_content = $file_content;

        $this->parsed_content = json_decode($this->file_content, true);
    }
523486
protected function checkFileHeader($content, $header, $name)
    {
        $len = strlen($header);
        $flag = substr($content, 0, $len);
        if ($flag != $header) {
            throw new \Exception("$name 文件已损坏");
        }
        return substr($content, $len);
    }
22154
public function getFileName($source_name, $type, $tmp_name, $index, $content_range, FileUpload $upload)
    {
        $this->filesystem = $upload->getFileSystem();
        $this->pathresolver = $upload->getPathResolver();

        $source_name = $this->getSluggedFileName($source_name);
        $uniqueFileName = $this->getUniqueFilename($source_name, $type, $index, $content_range);

        return $this->getSluggedFileName($uniqueFileName);
    }
1346924
function load_file($file_name, $prepend_path = true)
	{
		if ($prepend_path && $this->_config_path != "")
		$config_file = $this->_config_path . $file_name;
		else
		$config_file = $file_name;

		ini_set('track_errors', true);
		$fp = @fopen($config_file, "r");
		if (!is_resource($fp)) {
			$this->_trigger_error_msg("Could not open config file '$config_file'");
			return false;
		}

		$contents = ($size = filesize($config_file)) ? fread($fp, $size) : '';
		fclose($fp);

		$this->_config_data[$config_file] = $this->parse_contents($contents);
		return true;
	}
973142
public function file(String $name = NULL, Bool $multiple = false, Array $_attributes = [])
    {
        if( ! empty($this->settings['attr']['multiple']) )
        {
            $multiple = true;
        }

        $name = $this->settings['attr']['name'] ?? $name;

        if( $multiple === true )
        {
            $this->settings['attr']['multiple'] = 'multiple';
            $name = Base::suffix($name, '[]');
        }

        $this->commonMethodsForInputElements('file');

        return $this->_input($name, '', $_attributes, 'file');
    }