2008年11月19日 星期三

強制使用相對路徑,不使用絕對路徑

有時候跑crontab的時候,必需在程式裡使用絕對路徑。

來,看程式...
--
//一開始總是必要的
require '/home/www/config.php';
//或是這樣
require '../config.php'; //但這樣子在crontab不能跑
//當然,接下來的路徑就使用變數或常數來寫程式
require SOPILI_PATH.'/lib/db_connection.php';
view raw init.php hosted with ❤ by GitHub
--

但... 敗在第一行啊! 完全一點


--
<?php
require '../../config.php'; //原本是這樣
require dirname(__FILE__)."/../../config.php"; //改成這樣
view raw init.php hosted with ❤ by GitHub

留言