PHP下載google相冊(cè)到本地-PHP實(shí)例_PHP教程
推薦:如何用php連接mysql實(shí)例詳解一個(gè)簡單的通訊錄,數(shù)據(jù)庫的名字叫txl,數(shù)據(jù)庫只有一個(gè)表叫personal_info,表中有5個(gè)字段 pi_idpi_namepi_telpi_qqpi_email 首先我們要?jiǎng)?chuàng)建數(shù)據(jù)庫: create database txl; 然后我們建立表 CREATE TABLE `personal_info` ( `pi_id` bigint(20) NOT NULL auto_increment,
PHP下載google相冊(cè)到本地,調(diào)用方式xxx.php?user=xxx保證程序放的當(dāng)前目錄可寫文件夾可寫文件默認(rèn)存放方式為./用戶名/相冊(cè)1描述/圖片描述-1.圖片后綴lt;?phpfunctionopen$host,$file{$return=;$header='';...
調(diào)用方式 xxx.php?user=xxx
保證程序放的當(dāng)前目錄可寫文件夾 可寫文件
默認(rèn)存放方式為
./用戶名/相冊(cè)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相冊(cè)</title>
<form>
<input name=user type=text>
<input type=submit>
</form>
分享:通過php刪除xml文檔內(nèi)容的方法本文實(shí)例講述了通過php刪除xml文檔內(nèi)容的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下: 第一種情況:刪除一個(gè)student節(jié)點(diǎn) 代碼如下:?php //1、創(chuàng)建一個(gè)DOMDocument對(duì)象。該對(duì)象就表示 xml文件 $xmldoc = new DOMDocument(); //2、加載xml文件(指定要解析哪個(gè)xml文件
- 如何用php連接mysql實(shí)例詳解
- 通過php刪除xml文檔內(nèi)容的方法
- php操作xml入門之xml基本介紹及xml標(biāo)簽元素
- 通過php添加xml文檔內(nèi)容的方法
- DOM基礎(chǔ)及php讀取xml內(nèi)容操作的方法
- php使用正則表達(dá)式獲取圖片url的方法
- PHP中$_GET $_POST $_REQUEST區(qū)別介紹
- php中靜態(tài)類與靜態(tài)變量用法的區(qū)別分析
- PHP全排列算法實(shí)現(xiàn)程序代碼
- php頁面緩存方法小結(jié)
- php查詢mssql出現(xiàn)亂碼的解決方法
- PHP的包含文件函數(shù)require和include路徑總結(jié)
- 相關(guān)鏈接:
- 教程說明:
PHP教程-PHP下載google相冊(cè)到本地-PHP實(shí)例
。