How to get an image file from API in Symfony2

324 Views Asked by At

I would like to get an image from REST API by using file_get_content() and store in Symfony2. $image = file_get_contents('https://foobar, false, $context)

But I am stacked when I am trying to sage the file.

$image->move($app['config']['image_temp_realdir'], $filename);

This line cause "Error: Call to a member function move() on string".
I understand this file data is not a File entity, but how can I convert this into File Entity? Or any method I can use to get file instead of file_get_content()?

Thanks in advance to your help.

1

There are 1 best solutions below

0
On BEST ANSWER

Sorry, the problem resolved.

Saved the file by file_put_contents() and created new File.

file_put_contents($app['config']['image_temp_realdir'].'/'.$filename, $image); $file = new File($app['config']['image_temp_realdir'].'/'.$filename);