Http类在目录ThinkPHP/Lib/ORG/Net下面。接下来看看是如何调用的。
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'];
}
}
?>
这里我先判断数据库中有无该图片信息,没有就调用amazon的webservice从远程获取到图片地址,再使用
Http::curl_download($remoteUrl['ImageURL'], "./".$localUrl);
其中curl_download方法第一个参数是远程图片地址,第二个参数是保存到本地的地址。
OK,就这么简单~~
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn