Implementation code for downloading remote images to local using Http class that comes with ThinkPHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:25:52
Original
1493 people have browsed it

The Http class is under the directory ThinkPHP/Lib/ORG/Net. Next let's see how it is called.

Copy code 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 there is the image information in the database. If not, I call Amazon's webservice to obtain the image address remotely, and then use
to copy the code The code is as follows:

Http::curl_download($remoteUrl['ImageURL'], "./".$localUrl);

The first parameter of the curl_download method is the remote image address , the second parameter is the address saved to the local area.
OK, it’s that simple~~

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324070.htmlTechArticleHttp class is under the directory ThinkPHP/Lib/ORG/Net. Next let's see how it is called. Copy the code The code is as follows: ?php import("Com.Buyback.QueryAmazon"); import("ORG.Net.Http"); class Im...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!