通过index.php访问静态文件(js和css)
index.php
修改如下,但是会消耗服务器更多资源
// [ 应用入口文件 ]
if (strpos($_SERVER['PHP_SELF'], "index.php/static") > 0) {
$str = str_replace("/index.php", "", $_SERVER['PATH_TRANSLATED']);
if (strpos($_SERVER['PHP_SELF'], ".css") > 0) {
header('Content-type: text/css');
}
if (strpos($_SERVER['PHP_SELF'], ".js") > 0) {
header('Content-type: text/javascript');
}
if (strpos($_SERVER['PHP_SELF'], ".png") > 0) {
header('Content-Type: image/png');
}
if (strpos($_SERVER['PHP_SELF'], ".jpg") > 0) {
header('Content-Type: image/jpeg');
}
$myfile = fopen($str, "r") or die("Unable to open file!");
echo fread($myfile, filesize($str));
fclose($myfile);
// echo (file_get_contents($str));
} else {
// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';
}