PHP获取文件大小
//获取文件的大小 function getfilesize($file, $DataDir) { $perms = stat($DataDir . $file); $size = $perms['size']; // 单位自动转换函数 $kb = 1024; // Kilobyte $mb = 1024 * $kb; // Megabyte $gb = 1024 * $mb; // Gigabyte $tb = 1024 * $gb; // Terabyte if ($size < $kb) { return $size . " B"; } else if ($size < $mb) { return round($size / $kb, 2) . " KB"; } else if ($size < $gb) { return round($size / $mb, 2) . " MB"; } else if ($size < $tb) { return round($size / $gb, 2) . " GB"; } else { return round($size / $tb, 2) . " TB"; } }
PHP获取用户设备信息
/** * 获取用户设备信息 */ function equipmentSystem() { $agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; if (stristr($agent, 'iPad')) { $fb_fs = "iPad"; } else if (preg_match('/Android (([0-9_.]{1,3})+)/i', $agent, $version)) { $fb_fs = "手机(Android " . $version[1] . ")"; } else if (stristr($agent, 'Linux')) { $fb_fs = "电脑(Linux)"; } else if (preg_match('/iPhone OS (([0-9_.]{1,3})+)/i', $agent, $version)) { $fb_fs = "手机(iPhone " . $version[1] . ")"; } else if (preg_match('/Mac OS X (([0-9_.]{1,5})+)/i', $agent, $version)) { $fb_fs = "电脑(OS X " . $version[1] . ")"; } else if (preg_match('/unix/i', $agent)) { $fb_fs = "Unix"; } else if (preg_match('/windows/i', $agent)) { $fb_fs = "电脑(Windows)"; } else { $fb_fs = "Unknown"; } return $fb_fs; }
PHP获取网站域名
/** * 获取网站域名 * @return string 网站域名 */ function getWebUrl() { /* 协议 */ $protocol = 'http://'; /* 域名或IP地址 */ if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { $host = $_SERVER['HTTP_X_FORWARDED_HOST']; } elseif (isset($_SERVER['HTTP_HOST'])) { $host = $_SERVER['HTTP_HOST']; } else { /* 端口 */ if (isset($_SERVER['SERVER_PORT'])) { $port = ':' . $_SERVER['SERVER_PORT']; if ((':80' == $port & 'http://' == $protocol) || (':443' == $port & 'https://' == $protocol)) { $port = ''; } } else { $port = ''; } if (isset($_SERVER['SERVER_NAME'])) { $host = $_SERVER['SERVER_NAME'] . $port; } elseif (isset($_SERVER['SERVER_ADDR'])) { $host = $_SERVER['SERVER_ADDR'] . $port; } } return $protocol . $host; }
PHP获取客户端ip
/** * 获取客户端ip */ function getIP() { if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP"); else if (getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR"); else if (getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR"); else $ip = "Unknow"; return $ip; }
发表评论: