我可以在不启用fopen包装器的情况下将URL用作imagecreatefromjpeg()的源吗? [英] Can I use a URL as the source for imagecreatefromjpeg() without enabling fopen wrappers?

查看:79
本文介绍了我可以在不启用fopen包装器的情况下将URL用作imagecreatefromjpeg()的源吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以使用带有URL的imagecreatefromjpeg(),imagecreatefrompng()等作为fopen()的文件名",但是由于安全问题,我无法启用包装器.有没有办法在不启用URL的情况下将URL传递给imagecreatefromX()?

I know it’s possible to use imagecreatefromjpeg(), imagecreatefrompng(), etc. with a URL as the ‘filename’ with fopen(), but I'm unable to enable the wrappers due to security issues. Is there a way to pass a URL to imagecreatefromX() without enabling them?

我也尝试过使用cURL,这也给我带来了问题:

I’ve also tried using cURL, and that too is giving me problems:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://www.../image31.jpg"); //Actually complete URL to image
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);

$image = imagecreatefromstring($data);
var_dump($image);

imagepng($image);
imagedestroy($image);

推荐答案

您可以使用cURL下载文件,然后将结果通过管道传输到imagecreatefromstring.

You can download the file using cURL then pipe the result into imagecreatefromstring.

示例:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $imageurl); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // good edit, thanks!
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); // also, this seems wise considering output is image.
    $data = curl_exec($ch);
    curl_close($ch);

    $image = imagecreatefromstring($data);

这篇关于我可以在不启用fopen包装器的情况下将URL用作imagecreatefromjpeg()的源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆