ueditor 无法远程抓取微信公众号文章图片的Bug解决方法
微wx笑
2020-03-31【网页网站】
1130
9
0关键字:
ueditor 微信公众号
转载文章的时候,我们希望通过服务器把图片抓取下来存到本地服务器上,以防止原文及图片删除后,转载的文章无法显示图片。但是今天发现在抓取图片的时候失败了,原因是图片的 Conte
转载文章的时候,我们希望通过服务器把图片抓取下来存到本地服务器上,以防止原文及图片删除后,转载的文章无法显示图片。但是今天发现在抓取图片的时候失败了,原因是图片的 Content-Type 是application/octet-stream,导致验证失败,所以没有抓取成功。
解决方法:
1、修改 Uploader.class.php 文件中的验证部分,增加application/octet-stream 类型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | //格式验证(扩展名验证和Content-Type验证) if (!isset( $heads [ 'Content-Type' ]) || (! stristr ( $heads [ 'Content-Type' ], "image" ) && ! stristr ( $heads [ 'Content-Type' ], "application/octet-stream" ))) { $this ->stateInfo = $this ->getStateInfo( "ERROR_HTTP_CONTENTTYPE" ). $heads [ 'Content-Type' ]; return ; } else { if ( count ( $this ->config[ 'allowFiles' ]) > 0){ $fileType = strtolower ( strrchr ( $imgUrl , '.' )); if ( strpos ( $fileType , "?" )){ $fileType = strstr ( $fileType , "?" , true); } if (!in_array( $fileType , $this ->config[ 'allowFiles' ])){ //$this->stateInfo = $this->getStateInfo("ERROR_HTTP_ALLOWFILES"); //return; } } } |
2、处理扩展名的问题
由于 Content-Type 后面的部分是 octet-stream,不是真正的扩展名,所以给一个默认的扩展名 png,虽然可能不一定完全正确,但现在的浏览器基本都能正确显示。
1 2 3 4 5 6 7 8 9 10 11 12 13 | $this ->oriName = $m ? $m [1]: "" ; if (! strpos ( $this ->oriName, "." )){ if ( strpos ( $heads [ 'Content-Type' ], '/' )){ $extn = substr ( $heads [ 'Content-Type' ], strpos ( $heads [ 'Content-Type' ], '/' )+1); if ( stristr ( $extn , "octet-stream" )){ $this ->oriName .= ".png" ; } else { $this ->oriName .= "." . $extn ; } } else { $this ->oriName .= ".png" ; } } |
本文由 微wx笑 创作,采用 署名-非商业性使用-相同方式共享 4.0 许可协议,转载请附上原文出处链接及本声明。
原文链接:https://www.ivu4e.cn/blog/web/2020-03-31/366.html