0x00000050 Computer blue screen code implemented in PHP to get the pictures in the Web page and save to the local code

Source: Internet
Author: User
Copy CodeThe code is as follows:


Header ("Content-type:image/jpeg");
function Read_url ($STR)
{
$file =fopen ($str, "R");
while (!feof ($file))
{
$result. =fgets ($file, 9999);
}
Fclose ($file);
return $result;
}
function Save_img ($STR)
{
$result =read_url ($STR);
$result =str_replace ("\" "," ", $result);
$result =str_replace ("\" "," ", $result);
Preg_match_all ('/|>)/I ', $result, $matches);
foreach ($matches [1] as $value)
{
echo $value. "
\ n ";
Grabimage ($value, $filename = "");
}
}
$url is the full URL address of the remote picture and cannot be empty.
$filename is an optional variable: If blank, the local file name will be based on the time and date
Automatically generated.
function Grabimage ($url, $filename = "") {
if ($url = = ""): return false;endif;
$path = "download/"; Specify Storage Folder
If the file does not exist, it is created;
if (!file_exists ($path)) {
mkdir ($path);
}
if ($filename = = "") {
$ext =STRRCHR ($url, ".");
if ($ext! = ". gif" && $ext! = ". jpg"): return false;endif;
$filename = $path. Date ("Dmyhis"). $ext;
}
Ob_start ();
ReadFile ($url);
$img = Ob_get_contents ();
Ob_end_clean ();
$size = strlen ($img);
$FP 2= @fopen ($filename, "a");
Fwrite ($fp 2, $img);
Fclose ($fp 2);
return $filename;
}
Save_img ("Http://www.jb51.net");
?>

The above describes the 0x00000050 computer blue screen code implemented in PHP to obtain the picture in the Web page and saved to the local code, including the 0x00000050 computer blue screen code content, I hope the PHP tutorial interested in a friend helpful.

  • 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.