Return image in array bytes format from URL on the internet?

0

Let's say I have this URL for the image:

  

link

How can I get an array of bytes of this image?

I edit to add information about what I have tried but it does not work for me:

I've done this:

$filename = 'https://www.nissan-cdn.net/content/dam/Nissan/global/vehicles/gt-r/r35/eulhd/2_minor_change/overview/17TDIeulhd_GTRHelios026.jpg.ximg.l_full_m.smart.jpg';
$url = preg_replace("/ /", "%20", $filename);
$file = fopen($url, "rb");
$contents = fread($file, filesize($url));
fclose($file);

And I get the following error:

  

Warning: filesize (): stat failed for image direction

    
asked by Pavlo B. 13.03.2018 в 11:40
source

1 answer

1

I think you can use file_get_contents for that:

$filename = 'https://www.nissan-cdn.net/content/dam/Nissan/global/vehicles/gt-r/r35/eulhd/2_minor_change/overview/17TDIeulhd_GTRHelios026.jpg.ximg.l_full_m.smart.jpg';

$cadena = file_get_contents(urlencode($filename));

But passing the filename by urlencode, to adjust cases of blanks and others.

If you need the readable string, you can pass it through base64_encode:

$result = base64_encode($cadena);

But keep in mind that there will be cases that do not allow you to read the file directly, for CORS topics ( link ). In this case it seems that you will have no problem, but be careful with it.

    
answered by 13.03.2018 / 12:02
source