PHP下载google相册到本地-PHP实例
来源: 阅读:719 次 日期:2015-02-02 15:51:55
温馨提示: 小编为您整理了“PHP下载google相册到本地-PHP实例”,方便广大网友查阅!

PHP下载google相册到本地,调用方式xxx.php?user=xxx保证程序放的当前目录可写文件夹可写文件默认存放方式为./用户名/相册1描述/图片描述-1.图片后缀lt;?phpfunctionopen$host,$file{$return=;$header='';...

调用方式 xxx.php?user=xxx

保证程序放的当前目录可写文件夹 可写文件

默认存放方式为

./用户名/相册1描述/图片描述-1.图片后缀<?php

function open($host,$file){

$return = "";

$header = '';

while($header!='200'){

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

if (!$fp) {

echo "$errstr ($errno)<br />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)<br />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 "can't open $filename";

exit;

}

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

echo "can't write $filename";

exit;

}

// echo "write to $filename done";

fclose($handle);

echo $filename."<br />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 can't 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 '<meta http-equiv="refresh" content="2;url=?aid='.$aid.'&user='.$user.'">';

?>

<title>下载google相册</title>

<form>

<input name=user type=text>

<input type=submit>

</form>

更多信息请查看IT技术专栏

更多信息请查看网络编程
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!

2025国考·省考课程试听报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:
咨询QQ:526150442(9:00—18:00)版权所有:
云南网警报警专用图标
Baidu
map