我已經找到圖片偵測EXIF資訊問題 請問一下 我該如何寫入資料庫 能讓PLOG網頁能夠搜尋出來在展示在首頁頁面像搜尋文章一樣
假設 我有一張圖片 它的焦長: 5.8mm 我只要在搜尋上面打上5.8 或焦長
搜尋頁面就能夠把有關 焦長: 5.8mm 圖片跟資訊顯示出來
<body bgcolor='#cccccc'>
<center>
<a href=index.html>回首頁</a><br><br><br>
<?
global $files_array;
$files_array= array();
$epaper_path = "$dd/";
$readmefile=$epaper_path."readme.txt";
if ( $fp=@file($readmefile)) {
$fp=file($readmefile);
} ;
echo "<H1>".$fp[0]."</h1><br>";
if ($dh = opendir($epaper_path)) { //打開資料夾
$files = array(); //將變數$files設定成陣列
while (($file = readdir($dh)) !== false) { //先設一個陣列變數 等等資料夾裡面所有檔名當丟進去這個陣列
if ((substr($file, strlen($file) - 4) == '.jpg') or (substr($file, strlen($file) - 4) == '.JPG')) {
array_push($files, $file);
}
}
closedir($dh);
}
sort($files); //將陣列排序整理一下
$ss=1;
foreach ($files as $file){ //將檔名輸出
$title = Title($file);
//include(''); // 頁首
echo "<table border=0 align=center cellpadding=2 cellspacing=2><tr><td align=center>";
// echo "<table border=0 cellpadding=1 cellspacing=1><tr><th>";
// echo "<img src='/images/dot_l2.gif' width='14' height='14' align='absmiddle'>";
echo "<font color='#ff6600'><b>[#".$ss."]".$fp[$ss]."</b></font>";
echo "</td></tr><tr><td align=center>";
echo "<img src=$dd"."/{$file} alt='$file' border='1'>";
echo showEXIF($dd."/".$file);
echo "<br><br>檔案夾
<b>$dd</b>]-檔名
<b>$file</b>]<br><br><br>";
echo "</td></tr><tr><td align=center>";
echo "</td></tr>";
echo "</table><br>";
$ss++;
}
echo "<H1>".$fp[$ss]."</h1><br>";
//------------------處理檔案名稱--------------------------
function Title($filename) {
$title = substr($filename, 0, strlen($filename) - 4);
$title = str_replace('-', ' ', $title);
$title = ucwords($title);
return $title;
}
echo "<a href=index.html>回首頁</a>";
//------------------處理EXIF--------------------------
function showEXIF($path){
if (function_exists('read_exif_data')){
$exif = @read_exif_data($path,0,true);
if ($exif['EXIF']['ExifVersion']){
$nodata="<FONT STYLE=\"color:gray;font:8pt Arial\">N/A</FONT>";
$attach_exif ="<SPAN STYLE=\"height:1px;margin:1px 0 8px;border:0;font:8pt/120% 'MS Gothic',Tahoma;color:#005000\"><FONT STYLE=\"color:black;font:8pt 'MS Gothic'\">EXIF ".sprintf("%1.2f",(float)$exif['EXIF']['ExifVersion']/100)." - </FONT><SPAN STYLE=\"border-bottom:1px solid #0080C0;height:1px;margin:0;padding:2px 0 0 0\">";
$attach_exif.="<FONT STYLE=\"font-family:Tahoma;color:black\">".$exif['IFD0']['Model']."</FONT> ";
if(empty($exif['EXIF']['ExposureProgram']))$exif['EXIF']['ExposureProgram']=$nodata;
else{
switch($exif['EXIF']['ExposureProgram']){
case 1:$exif['EXIF']['ExposureProgram'] = "手動(M)";break;//Manual Control
case 2:$exif['EXIF']['ExposureProgram'] = "程式自動(P)";break;//Program Normal
case 3:$exif['EXIF']['ExposureProgram'] = "光圈先決(A)";break;//Aperture Priority
case 4:$exif['EXIF']['ExposureProgram'] = "快門先決(S)";break;//Shutter Priority
case 5:$exif['EXIF']['ExposureProgram'] = "慢速快門";break;//Program Creative (Slow Program)
case 6:$exif['EXIF']['ExposureProgram'] = "運動模式";break;//Program Action(High-Speed Program)
case 7:$exif['EXIF']['ExposureProgram'] = "人像";break;//Portrait
case 8:$exif['EXIF']['ExposureProgram'] = "風景";//Landscape
}
}
$attach_exif.="<FONT STYLE=\"color:black;font:8pt 'MS Gothic'\">曝光模式:</FONT>".$exif['EXIF']['ExposureProgram'];
if(empty($exif['EXIF']['MeteringMode']))$exif['EXIF']['MeteringMode']=$nodata;
else{
switch($exif['EXIF']['MeteringMode']){
case 0 :$exif['EXIF']['MeteringMode'] = "未知";break;
case 1 :$exif['EXIF']['MeteringMode'] = "Average";break;
case 2 :$exif['EXIF']['MeteringMode'] = "中央重點測光";break;
case 3 :$exif['EXIF']['MeteringMode'] = "點測光";break;
case 4 :$exif['EXIF']['MeteringMode'] = "多重點測光";break;
case 5 :$exif['EXIF']['MeteringMode'] = "Multi-Segment";break;
case 6 :$exif['EXIF']['MeteringMode'] = "Partial";break;
case 255:$exif['EXIF']['MeteringMode'] = "其它";break;
}
}
$attach_exif.="<FONT STYLE=\"color:black;font:8pt 'MS Gothic'\"> 測光:</FONT>".$exif['EXIF']['MeteringMode']."";
$attach_exif.="<FONT STYLE=\"color:black;font:8pt 'MS Gothic'\"> 白平衡:</FONT>".$exif['EXIF']['WhiteBalance']."</SPAN><BR> <SPAN STYLE=\"height:1px;margin:0;padding:2px 0 0 0\">";
if(empty($exif['COMPUTED']['ApertureFNumber']))$exif['COMPUTED']['ApertureFNumber']=$nodata;
$attach_exif.="<FONT STYLE=\"color:black;font:8pt 'MS Gothic'\">光圈:</FONT>".ereg_replace("f/","F",$exif['COMPUTED']['ApertureFNumber'])."";
if(empty($exif['EXIF'][ExposureTime])){
$exif['EXIF'][ExposureTime]=$nodata;
}else{
$exif['EXIF'][ExposureTime]=explode("/",$exif['EXIF'][ExposureTime]);
if(($exif['EXIF'][ExposureTime][0]/$exif['EXIF'][ExposureTime][1])>=1)
$exif['EXIF'][ExposureTime]=sprintf("%.1f Sec",(float)$exif['EXIF'][ExposureTime][0]/$exif['EXIF'][ExposureTime][1]);
else
$exif['EXIF'][ExposureTime]=sprintf("1/%d Sec",$exif['EXIF'][ExposureTime][1]/$exif['EXIF'][ExposureTime][0]);
}
$attach_exif.="<FONT STYLE=\"color:black;font:8pt 'MS Gothic'\"> 快門:</FONT>".$exif['EXIF'][ExposureTime]."";
if(empty($exif['EXIF'][ISOSpeedRatings]))$exif['EXIF'][ISOSpeedRatings]=$nodata;
$attach_exif.="<FONT STYLE=\"color:black;font:8pt 'MS Gothic'\"> ISO:</FONT>".$exif['EXIF'][ISOSpeedRatings]."";
if(empty($exif['EXIF'][ExposureBiasValue])){
$exif['EXIF'][ExposureBiasValue]=$nodata;
}else{
$exif['EXIF'][ExposureBiasValue]=explode("/",$exif['EXIF'][ExposureBiasValue]);
$exif['EXIF'][ExposureBiasValue]=sprintf("%1.1f EV",((float)$exif['EXIF'][ExposureBiasValue][0]/$exif['EXIF'][ExposureBiasValue][1]*100)/100);
if((float)$exif['EXIF'][ExposureBiasValue]>0)$exif['EXIF'][ExposureBiasValue]="+".$exif['EXIF'][ExposureBiasValue];
}
$attach_exif.="<FONT STYLE=\"color:black;font:8pt 'MS Gothic'\"> 曝光補償:</FONT>".$exif['EXIF'][ExposureBiasValue]."";
if(empty($exif['EXIF'][FocalLength])){
$exif['EXIF'][FocalLength]=$nodata;
}else{
$exif['EXIF'][FocalLength]=explode("/",$exif['EXIF'][FocalLength]);
$exif['EXIF'][FocalLength]=sprintf("%4.1fmm",(double)$exif['EXIF'][FocalLength][0]/$exif['EXIF'][FocalLength][1]);
}
$attach_exif.="<FONT STYLE=\"color:black;font:8pt 'MS Gothic'\"> 焦長:</FONT>".$exif['EXIF'][FocalLength]."</SPAN></SPAN>";
}
}
return $attach_exif;
}
?>