function GetImage ($url, $save _dir= ', $filename = ') {if (trim ($url) = = ") {return array (' file_name ' => ', ' Save_path ')
=> ', ' Error ' =>1);
} if (Trim ($save _dir) = = ') {$save _dir= ' media/img/film '; ' If (trim ($filename) = = ') {//save file $filename = $this->uuid (). ". JPG ";
The default filename, you can modify according to their own needs} if (0!==strrpos ($save _dir, '/')) {$save _dir.= '/'; //Create the Save directory if (!file_exists ($save _dir) &&!mkdir ($save _dir,0777,true)) {return array (' file_name ' => $filenam
E, ' Save_path ' => ', ' Error ' =>5);
The method used to obtain the remote file $ch =curl_init ();
$timeout = 5;
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, curlopt_returntransfer,1);
curl_setopt ($ch, Curlopt_connecttimeout, $timeout);
$img =curl_exec ($ch);
Curl_close ($ch);
$size =strlen ($IMG);
File size $fp 2= @fopen ($save _dir. $filename, ' a ');
$r = Fwrite ($fp 2, $img);
if (! $r) return false;
Fclose ($fp 2);
Unset ($img, $url);
Return $save _dir. $filename; Here to get the picture when in addition to using curl, you can also use file_get_contents ();
For example: <span style= "font-family:arial, Helvetica, Sans-serif;" > This is only abbreviated to get and save, do not do other verification operations, please add yourself. </span><pre name= "code" class= "PHP" > $url = "HTTP://TP3.SINAIMG.CN/3173430994/180/5723887556/1";
$r = file_get_contents ($url);
$fopen = fopen ("E:\\icon.jpg", "a");
$ret = fwrite ($fopen, $r);
Fclose ($fopen);