首页 > PHP

PHP下载google相册到本地

时间:2009-04-23 13:01:10  作者:chinaitlab  我要投稿
Linux初探欢迎您的投稿,投放方法请点击这里查看,我们会定期赠送精美小礼品给优秀的投稿作者。海纳百川 取则行远!LinuxGoo欢迎您的到来。
调用方式 xxx.php?user=xxx保证程序放的当前目录可写文件夹 可写文件默认存放方式为./用户名/相册1描述/图片描述-1.图片后缀<?phpfunction open($host,$file){$r......

调用方式 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.1\r\n";

$out .= "Host: $host\r\n";

$out .= "P3P: CP=\"CAO PSA OUR\"\r\n";

$out .= "User-Agent: Baiduspider ( [url]http://www.baidu.com/search/spider.htm[/url])\r\n";

$out .= "Connection: Close\r\n\r\n";

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("/\r\n\r\n(. )/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.1\r\n";

$out .= "Host: $host\r\n";

$out .= "User-Agent: Baiduspider ( [url]http://www.baidu.com/search/spider.htm[/url])\r\n";

$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);

while (!feof($fp)) {

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

}

fclose($fp);

}

preg_match("/HTTP\/1.0 (.*?) /",$return,$output);

$header = $output[1];

}

preg_match("/\r\n\r\n(. )/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 ')) {

如果您需转载 PHP下载google相册到本地,请注明来自LinuxGoo.com,其版权归原作者所有。请广大网友留言时遵纪守法,使用文明用语。如果您在应用中有什么问题,请在下面留言,我们会尽快解答。
来顶一下
近回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
栏目热门