Use the Http class that comes with ThinkPHP to download the remote image to the local implementation code. The Http class is under the ThinkPHPLibORGNet directory. Next, let's take a look at how to call it. Copy the code as follows :? Phpimport (Com. Buyback. QueryAmazon); import (ORG. Net. Http); classIm Http class is under the ThinkPHP/Lib/ORG/Net directory. Next, let's take a look at how to call it.
The code is as follows:
Import ("Com. Buyback. QueryAmazon ");
Import ("ORG. Net. Http ");
Class Image {
Public static function getImage ($ isbn ){
$ BookInformModel = D ("bookinform ");
$ Result = $ bookInformModel-> where ("isbn = '$ isbn'")-> select ();
If ($ result [0] ['image'] = ""){
$ Data ['inform _ id'] = $ result [0] ['inform _ id'];
$ RemoteUrl = QueryAmazon: getImage ($ isbn );
If (! Empty ($ remoteUrl ['imageurl']) {
$ LocalUrl = "Public/bookcover/". $ isbn. ". jpg ";
Http: curl_download ($ remoteUrl ['imageurl'], "./". $ localUrl );
} Else {
$ LocalUrl = "Public/bookcover/unknownbook.png ";
}
$ Data ['image'] = $ localUrl;
$ BookInformModel-> save ($ data );
Return $ localUrl;
}
Return $ result [0] ['image'];
}
}
?>
Here, I first determine whether the image information is in the database. if not, I call amazon's webservice to remotely obtain the image address and then use
The code is as follows:
Http: curl_download ($ remoteUrl ['imageurl'], "./". $ localUrl );
The first parameter of the curl_download method is the remote image address, and the second parameter is the local address.
OK, that's simple ~~
Bytes. Next, let's take a look at how to call it. The code is as follows :? Php import ("Com. Buyback. QueryAmazon"); import ("ORG. Net. Http"); class Im...