หาไดเร็คทอรี่ temp ของ server

ฟังก์ชั่นการหาไดเร็คทอรี่ Temp ของ Server ซึ่งเป็นที่ๆไฟล์จะถูกอัปโหลดไปพักไว้ก่อนบน Server

<?
  if ( !function_exists('sys_get_temp_dir') ) {
    function sys_get_temp_dir() {
      //อ่านจากตัวแปรระบบ
      if ( !empty($_ENV['TMP']) ) {
        return realpath( $_ENV['TMP'] );
      } else if ( !empty($_ENV['TMPDIR']) ) {
        return realpath( $_ENV['TMPDIR'] );
      } else if ( !empty($_ENV['TEMP']) ) {
        return realpath( $_ENV['TEMP'] );
      } else { //ใช้ tempory ของ วินโดวส์
        $temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' );
        if ( $temp_file ) {
          $temp_dir = realpath( dirname($temp_file) );
          unlink( $temp_file );
          return $temp_dir;
        } else {
          return FALSE;
        }
      }
    }
  }
  
  echo sys_get_temp_dir();
?>
ผู้เขียน goragod โพสต์เมื่อ 01 เม.ย. 2551 เปิดดู 4,954 ป้ายกำกับ PHP
^