php将文件转二进制的方法:首先设置“header( "content-type: image/jpeg");”;然后通过fopen和fread函数打开并读取文件;最后将图片文件以二进制流的形式输出到客户端即可。
推荐:《php教程》
php将文件转换成二进制输出
header( "content-type: image/jpeg");$psize = filesize('1.jpg');$picturedata = fread(fopen('1.jpg', "r"), $psize);echo $picturedata;就这么几句话,就将图片以二进制流的形式输出到客户端了,和打开一张图片没有任何区别,需要注意的是,发送的header要根据具体情况而定,不一定都是image/jpeg。jpg的是它,但png的就是image/png.不同的图片输出不同的头部。
用途:
oss默认支持上传文件流,但input表单默认是返回一个文件:
/ * 支持文件类型上传到oss */ public static function uploadfile($filename, $ext = 'jpg', $type = enum_oss_file_type::img) { $content = static::file2content($filename); return static::upload($content, $ext, $type); } public static function file2content($filename) { return fread(fopen($filename, 'r'), filesize($filename)); }
我司本案号下有两个网站和ssl证书如何安装,都有哪些申请步骤?网站注册信息怎么查?域名申请要注意哪些问题?云服务器ecs的购买步骤华为云服务器ecs是虚拟机吗买域名的网站哪个好 买域名要注意哪些问题阿里云服务器会自动续费吗这3种无服务器缺点:云提供商绝对不会提及