Can I use the url as the source for imagecreatefromjpeg () without including fopen wrappers?

I know that it can be used with imagecreatefromjpeg (), imagecreatefrompng (), etc. with the url as the file name with fopen (), but I cannot enable shells due to security issues. Is there a way to pass the imagecreatefromX () url without their permission?

Ive also tried using cURL, and this also gives 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); 
+7
source share
3 answers

You can upload the file using cURL and then pass the result to imagecreatefromstring .

Example:

  $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); 
+17
source

You can even implement a cURL-based stream wrapper for 'http' using stream_wrapper_register .

+1
source

You can always load an image (e.g. cURL) into a temporary file, and then load the image from that file.

0
source

All Articles