php抓取网页连接函数( 图片,就修改header头fopen打开文件后得到不是字符串直接输出要fgets)
优采云 发布时间: 2021-11-14 08:17php抓取网页连接函数(
图片,就修改header头fopen打开文件后得到不是字符串直接输出要fgets)
header('Content-Type: application/pdf'); // PDF文件
$fp = fopen($ret->url, "rb"); //二进制方式打开文件
fpassthru($fp); // 输出至浏览器
exit;
如果是图片,修改header
header('Content-Type: text/html; charset=utf-8'); //网页编码
15 header('Content-Type: text/plain'); //纯文本格式
16 header('Content-Type: image/jpeg'); //JPG、JPEG
17 header('Content-Type: application/zip'); // ZIP文件
18 header('Content-Type: application/pdf'); // PDF文件
19 header('Content-Type: audio/mpeg'); // 音频文件
20 header('Content-type: text/css'); //css文件
21 header('Content-type: text/javascript'); //js文件
22 header('Content-type: application/json'); //json
23 header('Content-type: application/pdf'); //pdf
24 header('Content-type: text/xml'); //xml
25 header('Content-Type: application/x-shockw**e-flash'); //Flash*敏*感*词*
fopen打开文件后,不是字符串,不能直接输出。 fgets() 函数用于获取字符串。 fgets() 函数从文件指针读取一行。文件指针必须有效,并且必须指向由 fopen() 或 fsockopen() 成功打开的文件(并且尚未被 fclose() 关闭)。
File_get_contents() 打开网页后会返回一个字符串,可以直接输出。