2013年4月9日 星期二

ini_set error 、DIRECTORY_SEPARATOR

設定php發生錯誤的等級
ini_set('error_reporting', E_ALL);

ConstantDescriptionNote
E_NOTICERun-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
E_STRICTEnable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.Since PHP 5 but not included in E_ALL until PHP 5.4.0
E_ALLAll errors and warnings, as supported, except of level E_STRICT prior to PHP 5.4.0.


ini_set('error_reporting', E_ALL);
ini_set('track_errors', '1');
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');

DIRECTORY_SEPARATOR

DIRECTORY_SEPARATOR是php的內部常量,用於顯示系統分隔符的命令,不需要任何定義與包含即可直接使用。在windows下路徑分隔符是\(當然/在部分系統上也是可以正常運行的),在linux上路徑的分隔符是/,這就導致了一個問題,比如伺服器是windows,有一個圖片上傳程序,伺服器上指定的上傳文件保存目錄是define('ROOT', dirname(__FILE__)."/upload");

於是php引入了DIRECTORY_SEPARATOR變量,可以將上面的寫法改寫为:
define('ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR."upload");

引申閱讀:


  1.     上傳圖片
  2.    上傳檔案簡易版

沒有留言: