Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Save / Cache image from URL
  • I'm working with a movie api that gives me the image url. How do I save or cache the actual image locally on my server?
  • Fetch the file using file_get_contents() or through Request::forge('your-url', 'curl')->execute();
  • Thanks for your response! The Request::forge doesn't seem to do anything and honestly that doesn't really make sense to me. Are you sure these are ways for me to _save_ the image to my server? I basically need to find a function or method that allows me to do: Cache::set('my_image_name', 'external_image_url'); so that I can begin to save these images locally so I don't have to pull from some external source every time I want to display a movie image.
  • You need to download the image first, it's pretty pointless to cache the url. The most obvious method to fetch it is file_get_contents(), but not every host has that enabled. Alternative is curl, which can be used to fetch remote data without problems. Note that if you store it in cache instead of on disk, you need a controller that serves up the image, instead of a direct link to the image on disk.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion