TP5 通过入口文件访问资源文件

通过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';
}

猜你喜欢

转载自blog.csdn.net/hd2killers/article/details/80829415
今日推荐