thinkpad x200 7457 uses the Http class that comes with ThinkPHP to download remote images to the local implementation code

WBOY
Release: 2016-07-29 08:46:24
Original
1573 people have browsed it

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

Copy the codeThe 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, and if not, call Amazon's webservice to obtain it remotely Go to the image address and use

to copy the codeThe code is as follows:


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


The curl_download method is the first The first parameter is the remote image address, and the second parameter is the address saved locally.
OK, it’s that simple~~

The above introduces the implementation code of thinkpad x200 7457 using the Http class that comes with ThinkPHP to download remote images to the local area, including the content of thinkpad x200 7457. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
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!