Home  >  Article  >  Backend Development  >  thinkpad x200 7457 uses the Http class that comes with ThinkPHP to download remote images to the local implementation code

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

WBOY
WBOYOriginal
2016-07-29 08:46:241615browse

The Http 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:


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 code The 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.

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