Home > Backend Development > PHP Tutorial > Download Google Photos to local PHP_PHP tutorial

Download Google Photos to local PHP_PHP tutorial

WBOY
Release: 2016-07-13 17:37:52
Original
945 people have browsed it

Calling method xxx.php?user=xxx

Ensure that the current directory where the program is placed can have writable folders and writable files

The default storage method is

 ./Username/Album 1 Description/Picture Description-1. Picture 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 photo album

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486527.htmlTechArticleCalling method xxx.php?user=xxx Ensure that the current directory where the program is placed is a writable folder and the writable file is stored by default The method is ./username/album 1 description/picture description-1.Picture suffix?php function o...
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template