PHP下载google相册到本地-PHP实例_PHP教程
推荐:如何用php连接mysql实例详解一个简单的通讯录,数据库的名字叫txl,数据库只有一个表叫personal_info,表中有5个字段 pi_idpi_namepi_telpi_qqpi_email 首先我们要创建数据库: create database txl; 然后我们建立表 CREATE TABLE `personal_info` ( `pi_id` bigint(20) NOT NULL auto_increment,
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.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+')) {
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 />\r\n";
}
$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:public\n,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>
分享:通过php删除xml文档内容的方法本文实例讲述了通过php删除xml文档内容的方法。分享给大家供大家参考。具体实现方法如下: 第一种情况:删除一个student节点 代码如下:?php //1、创建一个DOMDocument对象。该对象就表示 xml文件 $xmldoc = new DOMDocument(); //2、加载xml文件(指定要解析哪个xml文件
- 相关链接:
- 教程说明:
PHP教程-PHP下载google相册到本地-PHP实例。