示例#1
0
 /**
  * Determine a writable directory for temporary files.
  *
  * Function's preference is the return value of sys_get_temp_dir(),
  * followed by your PHP temporary upload directory, followed by XAppCONTENT_DIR,
  * before finally defaulting to /tmp/
  *
  * In the event that this function does not find a writable location,
  * It may be overridden by the XAppTEMP_DIR constant.
  *
  *
  * @return string Writable temporary directory.
  */
 public static function get_temp_dir()
 {
     static $temp;
     xapp_import('xapp.Utils.Strings');
     if (defined('XAppTEMP_DIR')) {
         return XApp_Utils_Strings::trailingslashit(XAppTEMP_DIR);
     }
     if ($temp) {
         return XApp_Utils_Strings::trailingslashit($temp);
     }
     if (function_exists('sys_get_temp_dir')) {
         $temp = sys_get_temp_dir();
         if (@is_dir($temp) && self::is_writable($temp)) {
             return XApp_Utils_Strings::trailingslashit($temp);
         }
     }
     $temp = ini_get('upload_tmp_dir');
     if (@is_dir($temp) && self::is_writable($temp)) {
         return XApp_Utils_Strings::trailingslashit($temp);
     }
     $temp = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR);
     if (is_dir($temp) && self::is_writable($temp)) {
         return $temp;
     }
     $temp = '/tmp/';
     return $temp;
 }