I currently have this code:
$json = file_get_contents('http://openstates.org/api/v1/legislators/?active=true&state=fl&&chamber=upper&apikey=ba09e678541e4b6ea28348c4517a6d50');
$obj = json_decode($json);
foreach($obj as $index => $user)
echo $user->photo_url;
Works great at echoing the list. What I would like to do instead of echoing the information could I possibly take the links and download the image files?
Or instead of echoing save the names to a one big file list?
I have been trying all sorts of of stuff for the past 2 days. Any help would be greatly appreciated.
You have to try something. If you want to download the url you can use
file_put_contents('image_name', file_get_contents($user->photo_url))or you can open up a file and write all the names to it. Just typing “writing to file in php” will give you php documentation on
file_put_contentsandfopen. One can usefopento open a file for ewriting and write to that file usingfwrite