Created
December 14, 2015 12:50
-
-
Save sotoz/2bdda68983fa08b05ebd to your computer and use it in GitHub Desktop.
Fetch image with php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function grab_image($url,$saveto) | |
{ | |
$ch = curl_init ($url); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); | |
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
$raw=curl_exec($ch); | |
curl_close ($ch); | |
if(file_exists($saveto)){ | |
unlink($saveto); | |
} | |
$fp = fopen($saveto,'x'); | |
fwrite($fp, $raw); | |
fclose($fp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment