[PHP] header下載檔案 搭配資料庫

剛剛在 ECstart 看到有人詢問 header檔案下載錯誤 發現網站義工有回答到這個function,所以就紀錄下來了

function dl_file($file){

   //First, see if the file exists
   if (!is_file($file)) { die("404 File not found!"); }

   //Gather relevent info about file
   $len = filesize($file);
   $filename = basename($file);
   $file_extension = strtolower(substr(strrchr($filename,"."),1));

   //This will set the Content-Type to the appropriate setting for the file
  switch( $file_extension ) {
     case "pdf": $ctype="application/pdf"; break;
     case "exe": $ctype="application/octet-stream"; break;
     case "zip": $ctype="application/zip"; break;
     case "doc": $ctype="application/msword"; break;
     case "xls": $ctype="application/vnd.ms-excel"; break;
     case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
     case "gif": $ctype="image/gif"; break;
     case "png": $ctype="image/png"; break;
     case "jpeg":
     case "jpg": $ctype="image/jpg"; break;
     case "mp3": $ctype="audio/mpeg"; break;
     case "wav": $ctype="audio/x-wav"; break;
     case "mpeg":
     case "mpg":
     case "mpe": $ctype="video/mpeg"; break;
     case "mov": $ctype="video/quicktime"; break;
     case "avi": $ctype="video/x-msvideo"; break;

     //The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files)
     case "php":
     case "htm":
     case "html":
     case "txt": die("Cannot be used for ". $file_extension ." files!"); break;

     default: $ctype="application/force-download";
   }

   //Begin writing headers
   header("Pragma: public");
   header("Expires: 0");
   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
   header("Cache-Control: public");
   header("Content-Description: File Transfer");
   
   //Use the switch-generated Content-Type
   header("Content-Type: $ctype");

   //Force the download
   $header="Content-Disposition: attachment; filename=".$filename.";";
   header($header );
   header("Content-Transfer-Encoding: binary");
   header("Content-Length: ".$len);
   @readfile($file);
   exit;
}
php 

wordpress 留言被灌爆 – plugin – WP-ImgCode mod

今天有人問我,blog留言版被灌爆,都是廣告信,我想說 wordpress 不是有內建一個外掛 Akismet 這個外掛可以擋掉很多spam,讓你的留言版不至於有廣告信,不過還是可以加上留言版的驗證圖形,這樣會更安全一點。 今天找到一個國人改寫的 WordPress plugin – WP-ImgCode mod 這個還不錯用,安裝方式如下

安裝啟用
  1. 將解壓縮出來的 wp-imgcode 資料夾放到 WordPress 的 plugin 資料夾,預設為 wp-content/plugins。
  2. 在控制台中啟用這個 plugin。
加入驗證碼
  1. 開啟目前使用佈景的相關檔案,例如 comments.php。
  2. 在要顯示驗證碼的地方,加上這個程式碼:
ID); ?>
明天在去搞定別人的網站吧~ 先紀錄一下~

[PHP] 如何切割中文標題

今天看到酷!學園討論區,php版有人問說要如何切割中文字,結果我自己以前弄的一個function就貼了上去,如下

function cut_word($text, $num){
if(strlen($text) > $num) {
   for($i=0;$i<$num;$i++) {
      $ch=substr($text,$i,1);
      if(ord($ch)>127) $i++;
      }
      $text= substr($text,0,$i).".";
   }
   return $text;
}
[Read More]
php 

替代役不平等待遇 (續) 替代役長官 (廖秘書)

廖秘書是在成功嶺把我錄取的人,也是他的惡夢開始,回想起來:在我2006年2月9號入伍,然後經過一個禮拜,劉專門委員(目前為整理組組長)來到成功嶺來找尋他們所要的人才,當時我記的很清楚,口口聲聲說要linux人才,資訊類,可是我做了一年多,只有我這個替代役是在從事資訊服務,其他資訊類專長的替代役,全部都拿去鍵打資料,相當浪費替代役人才,在成功嶺退伍前,國史館台灣文獻館 來到成功嶺挑選人才,我還記的很清楚,我是被劉專門委員挑上的,可是在這短短的一年多,我跟他幹上好幾次,這裡不多說了,之後還要寫一篇for him。

[Read More]

替代役不平等待遇?替代役長官 (黃秘書)

替代役其實是一個蠻好的職位,可以不必去軍隊裏面,又可以貢獻給國家,可是很多單位申請替代役,好像都搞錯方向,把我們當勞工在操,什麼事情都叫替代役做,然後正職公務人員很涼,天天沒事做,看報紙,泡茶?說實在替代役的義務是輔助性質,也就是說幫正職公務人員處理一些雜事,可是好像本單位『國史館台灣文獻館』不是這樣認為,單位主管除了平實請替代役幫忙修電腦之外,下班之後還叫替代役去單位主管家裡修電腦,甚至幫忙下載東西,我想這是不太對的吧?

[Read More]

[FreeBSD] Smokeping 安裝 架設

昨天看到 sayya 的 firedragen 個人版,看到 smokeping 的一些圖片,還蠻帥的,就想到要架設來玩看看 安裝方式如下:

[FreeBSD][root][ ~ ]# cd /usr/ports/net/smokeping/ 進去之後

make install clean 然後底下是安裝好之後的訊息

NOTE: A set of sample configuration files have been installed: /usr/local/etc/smokeping/config /usr/local/etc/smokeping/smokemail /usr/local/etc/smokeping/basepage.html /usr/local/etc/smokeping/tmail You *MUST* edit these to suit your requirements. Please read the manpages ‘smokeping_install’ and ‘smokeping_config’ for further details on installation and configuration. If you are upgrading from a previous version of Smokeping, the manpage ‘smokeping_upgrade’ may be of help. Once configured, you can start SmokePing by adding: smokeping_enable=”YES” to /etc/rc.conf, and then running, as root: /usr/local/etc/rc.d/smokeping start To enable Apache web access, add the following to your /usr/local/etc/apache/httpd.conf: ScriptAlias /smokeping.cgi /usr/local/smokeping/htdocs/smokeping.cgi Alias /smokeimg/ /usr/local/smokeping/htdocs/img/ 上面就是寫:請在 /etc/rc.conf 加入 smokeping_enable=”YES” 然後編輯 /usr/local/etc/apache/httpd.conf 在最後面加上 ScriptAlias /smokeping.cgi /usr/local/smokeping/htdocs/smokeping.cgi Alias /smokeimg/ /usr/local/smokeping/htdocs/img/ 修改 根目錄底下權限 Options Indexes FollowSymLinks ExecCGI 然後底下這段原本mark,請把他取消 AddHandler cgi-script .cgi 然後最後加上 Options Indexes FollowSymLinks ExecCGI AllowOverride Limit Order Deny,Allow Deny from all Allow from 192.168 底下附上設定檔,DarkKiller 在 firedragen 版 的連結,不過連結已經失效,好顯自己有存檔 http://blog.wu-boy.com/wp-content/uploads/2007/04/smokeping.txt 最後 NCTU NetFlow’s somkeping demo: http://netflow.ntcu.net/smokeping/smokeping.cgi?target=Album

[Read More]

[Mysql] 資料庫備份[big5]utf8轉換成utf-8

其實在很多opensource底下的套裝軟體,資料庫預設都是用 utf8,我想這會造成在 phpMyAdmin 底下看到亂碼,然後自己之前也有遇到問題,然後又在網路上看到這篇 搶救 xdite.net 所用的奇技淫巧 裡面所寫的備份方式跟我在轉換 phpBB2 跟自己的 wordpress 一樣 大同小異,我還在想說有更好的解法說,看來是沒有,在 wordpress 底下,只能利用後台的資料庫備份,不然用phpMyAdmin的話,我想你備份出來也是沒用。

[Read More]

[SQL] SQL 進階搜尋寫法~ 一個很簡單的問題

最近在幫 國史館台灣文獻館 寫館內搜尋系統,然後遇到一個問題,晚上跟 sayya裡的大大 ghost 搞了很久,也佔用 ghost 大大很多時間,在這裡先感謝他大力相助~,他還說 這是他解決最久的問題,哈哈,問題如下

我先列出3個表格的欄位跟一些值 table1 class_id, class_title 1 name1 2 name2 table2 class_id, series_name 1 000001 1 000002 1 000003 2 001001 2 001002 2 001003 table3 group_id, group_name 1 000001 1 000002 1 000003 1 000004 2 001001 2 001002 2 001003 如果想要 table1 跟 table2 結合 只要下 sql語法一

############

ex:

Select * From table1 as t1, table2 as t2 where t1.class_id = t2.class_id && SUBSRTING(series_name,1,3) = ‘000’ ############ 如果想要 table1 跟 table3 結合 只要下 sql語法二

[Read More]