[991]PHP網站開發 進階應用技巧2
<?php
$dir=(empty($_GET['dir']))?"D:/xampplite/htdocs/11/test/uploads":$_GET['dir'];
//整個目錄圖片
function get_pic($dir) {
$files = glob( $dir . '*', GLOB_MARK );
foreach( $files as $file ){
if( is_dir( $file ) ){
$rss.=get_pic( $file );
}else{
$base_dir="D:/xampplite/htdocs/11/test/uploads";
$base_url="http://localhost/11/test/uploads";
$file=str_replace("\\","/",$file);
$url=str_replace($base_dir,$base_url,$file);
$ext=substr(strtolower($file),-3);
$ok=array("jpg","gif","png","peg","flv","mp4");
if(!in_array($ext,$ok)){
continue;
}
if($ext=="flv"){
$thumbnail_url=substr($url,0,-3)."png";
}else{
$thumbnail_url=$url;
}
$rss.="
<item>
<title>$file</title>
<media:description>$file</media:description>
<link>$file</link>
<media:thumbnail url=\"$url\"/>
<media:content url=\"$url\"/>
</item>
";
}
}
return $rss;
}
?>
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<?php echo get_pic($dir); ?>
</channel>
</rss>