Using Thinkphp's own HTTP class to download remote pictures to the local implementation code _php tips

Source: Internet
Author: User
The HTTP class is below the directory thinkphp/lib/org/net. Now let's see how it's called.
Copy Code code as follows:

<?php
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 if there is no this picture information in the database, do not call Amazon's WebService from the remote access to the image address, and then use
Copy Code code as follows:

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

The first parameter of the Curl_download method is the remote picture address, and the second parameter is the address that is saved to the local.
OK, it's so simple ~ ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.