Google album to local PHP download _ PHP Tutorial

Source: Internet
Author: User
Tags php download
Google album to local PHP download. Call method xxx. php? Userxxx ensures that the write folder in the current directory of the program can be written. the default storage mode is. user name album 1 description image description-1. image suffix? Phpfunctiono call method xxx. php? User = xxx

Make sure that the current directory of the program is writable.

The default storage mode is

./Username/album 1 description/Image description-1. image suffix

Function open ($ host, $ file ){

$ Return = "";

$ Header =;

While ($ header! = 200 ){

$ Fp = fsockopen ($ host, 80, $ errno, $ errstr, 30 );

If (! $ Fp ){

Echo "$ errstr ($ errno)
N ";

} Else {

$ Out = "GET $ file HTTP/1.1rn ";

$ Out. = "Host: $ hostrn ";

$ Out. = "P3P: CP =" cao psa our "rn ";

$ Out. = "User-Agent: Baiduspider + (+ [url] http://www.baidu.com/search/spider.htm#/url]) rn ";

$ Out. = "Connection: Closernrn ";

Fwrite ($ fp, $ out );

While (! Feof ($ fp )){

$ Return. = fgets ($ fp, 1024 );

}

Fclose ($ fp );

}

Preg_match ("/HTTP/1.1 (.*?) OK/", $ return, $ output );

$ Header = $ output [1];

}

Preg_match ("/rnrn (. +)/is", $ return, $ out );

$ Return = $ out [1];

Return mb_convert_encoding ($ return, "GB2312", "UTF-8 ");;

}

Function openimg ($ host, $ file ){

$ Return = "";

$ Header = 302;

While ($ header = 302 ){

$ Fp = fsockopen ($ host, 80, $ errno, $ errstr, 30 );

If (! $ Fp ){

Echo "$ errstr ($ errno)
N ";

} Else {

$ Out = "GET $ file HTTP/1.1rn ";

$ Out. = "Host: $ hostrn ";

$ Out. = "User-Agent: Baiduspider + (+ [url] http://www.baidu.com/search/spider.htm#/url]) rn ";

$ Out. = "Connection: Closernrn ";

Fwrite ($ fp, $ out );

While (! Feof ($ fp )){

$ Return. = fgets ($ fp, 1024 );

}

Fclose ($ fp );

}

Preg_match ("/HTTP/1.0 (.*?) /", $ Return, $ output );

$ Header = $ output [1];

}

Preg_match ("/rnrn (. +)/is", $ return, $ out );

$ Return = $ out [1];

If ($ header = 404) $ return =;

Return $ return;

}

Function img ($ host, $ file, $ dir, $ name ){

$ Data = openimg ($ host, $ file );

// Echo $ dir;

$ Blankimg = ../images/blank.jpg;

$ Filename = $ dir./. $ name;

// Echo $ filename;

If (! Is_dir ($ dir )){

If (! Mkdir ($ dir) die (create dir error );

}

// Echo $ data;

If (! $ Handle = fopen ($ filename, w + )){

Echo "cant open $ filename ";

Exit;

}

If (fwrite ($ handle, $ data) === FALSE ){

Echo "cant write $ filename ";

Exit;

}

// Echo "write to $ filename done ";

Fclose ($ handle );

Echo $ filename ."
Rn ";

}

$ Aid = ($ _ GET [aid]! = )? $ _ GET [aid]: 0;

$ User = $ _ GET [user];

If (! Is_dir ($ user )){

If (! Mkdir ($ user) die (create dir error );

}

If ($ user =) die ("user string cant be blank ");

$ Userstr =/. $ user ./;

$ Html = str_replace ("", open (picasaweb.google.com, $ userstr ));

Preg_match_all ("/, access: publicn, title :(.*?) N, url :(.*?) N, src/s ", $ html, $ album );

$ All = count ($ album [1]);

If ($ aid> $ all) die (OK );

$ Aurl = str_replace (x2F,/, $ album [2] [$ aid]);

$ Astr =./. $ user./. $ album [1] [$ aid];

$ Afile = str_replace (http://picasaweb.google.com, $ aurl );

$ Html = str_replace ($, open (picasaweb.google.com, $ afile ));

Preg_match_all ("/" summarytype ":" text "," summary ":"(.*?) "," Contenttype ":"(.*?) "," Contentsrc ":"(.*?) "," Link ":/s", $ html, $ pics );

$ Allpic = count ($ pics [3]);

For ($ I = 0; $ I <$ allpic; $ I ++ ){

$ Pic = $ pics [3] [$ I];

$ Typetemp = explode (., $ pic );

$ Type = $ typetemp [(count ($ typetemp)-1)];

$ Pname = $ pics [1] [$ I].-. $ I... $ type;

$ Temp = explode (ggpht.com, $ pic );

$ Imghost = str_replace (http: //, $ temp [0] .ggpht.com );

$ Imgfile = $ temp [1];

Img ($ imghost, $ imgfile, $ astr, $ pname );

}

$ Aid ++;

Echo ;

?>

Download google album

Why xxx. php? User = xxx: ensure that the current directory of the program is saved./username/album 1 description/Image description-1. what is the image suffix? Php function o...

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.