PHP下載google相冊到本地-PHP實(shí)例
來源:易賢網(wǎng) 閱讀:787 次 日期:2015-02-02 15:51:55
溫馨提示:易賢網(wǎng)小編為您整理了“PHP下載google相冊到本地-PHP實(shí)例”,方便廣大網(wǎng)友查閱!

PHP下載google相冊到本地,調(diào)用方式xxx.php?user=xxx保證程序放的當(dāng)前目錄可寫文件夾可寫文件默認(rèn)存放方式為./用戶名/相冊1描述/圖片描述-1.圖片后綴lt;?phpfunctionopen$host,$file{$return=;$header='';...

調(diào)用方式 xxx.php?user=xxx

保證程序放的當(dāng)前目錄可寫文件夾 可寫文件

默認(rèn)存放方式為

./用戶名/相冊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技術(shù)專欄

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:PHP下載google相冊到本地-PHP實(shí)例
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)