common.php 1.09 KB
<?php
error_reporting(0);
/*
 * @current_dir 当前目录
 */
function readjs($current_dir = './')
{
    /*
     * 处理例子:
     * [QUERY_STRING] => ?ui/lazyload-1.0.0.js,unit/globalInit-2.0.0.js
     */
    if (!is_dir($current_dir)){
        return ;
    }

    $Q = '?';
    $E = ',';

    $query_string = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';

    if (!$query_string){
        return ;
    }

    $pos = strrpos($query_string, $Q);
    if (false !== $pos) {
        $query_string = substr($query_string, $pos + strlen($Q));
    }

    $files = explode($E, $query_string);

    foreach ($files as $file) {

        $js = substr($file, -3);
        $css = substr($file, -4);

        if ($js !== '.js' &&  $css !== '.css'){
            return ;
        }

//        if ( $js === '.js'){
//            header("Content-type: application/x-javascript; charset=utf-8");
//        } elseif ($css === '.css'){
//            header("Content-type: text/css; charset=utf-8");
//        }

        if (is_file($file = $current_dir . $file)) {
            readfile($file);
        }
    }
}