|
<? Php
$ Url = "http://www.bkjia.com/uploadfile/2013/0905/20130905072615990.jpg ";
$ Filename = 'curl.gif ';
GetImg ($ url, $ filename );
/*
* @ Obtain the specified image locally using curl
* @ Complete image address
* @ Name of the file to be stored
*/
Function getImg ($ url = "", $ filename = ""){
If (is_dir (basename ($ filename ))){
Echo "The Dir was not exits ";
Return false;
}
// Remove the quotation marks above the URL Connection
$ Url = preg_replace ('/(? : ^ ['"] + | ['"/] + $)/', '', $ Url );
$ Hander = curl_init ();
$ Fp = fopen ($ filename, 'wb ');
Curl_setopt ($ hander, CURLOPT_URL, $ url );
Curl_setopt ($ hander, CURLOPT_FILE, $ fp );
Curl_setopt ($ hander, CURLOPT_HEADER, 0 );
Curl_setopt ($ hander, CURLOPT_FOLLOWLOCATION, 1 );
// Curl_setopt ($ hander, CURLOPT_RETURNTRANSFER, false); // return data in the form of data stream. If it is false, it is directly displayed.
Curl_setopt ($ hander, CURLOPT_TIMEOUT, 60 );
/* $ Options = array (
CURLOPT_URL => 'HTTP: // www.bkjia.com/uploadfile/2013/0905/20130905038515990.jpg ',
CURLOPT_FILE => $ fp,
CURLOPT_HEADER => 0,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_TIMEOUT => 60
);
Curl_setopt_array ($ hander, $ options );
*/
Curl_exec ($ hander );
Curl_close ($ hander );
Fclose ($ fp );
Return true;
}
?> |