RewriteRule ^((.*/js/)?.*\.js)$ combinejs.php?path=$1&pre=$2&type=js [NC,L,QSA]
RewriteCond %{REQUEST_URI} !\.js$
RewriteCond %{REQUEST_URI} !combinejs\.php$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://js.wcdn.cn/$1 [NC,L,QSA,R]
<?php
require_once 'combine/JSCombineProcessor.php';
//t4/home/js/comp/content/publisherTop.js
$path = @$_GET['path'];
//t4/home/js/
$pre = @$_GET['pre'];
//D:\sina\t4\home\js\comp\content\publisherTop.js
$real_path = realpath($path);
if($real_path == false) {
$path = str_replace("/js/" , "/js/conf/" , $path);
$real_path = realpath($path);
if($real_path == false) {
$uri = $_SERVER['REQUEST_URI'];
JSCombineProcessor::getOnlineSource($uri);
return;
}
}
header ( 'Content-Type:application/x-javascript;Charset=UTF-8' );
//D:/sina/t4/home/js/comp/content/publisherTop.js
$real_path = str_replace('\\' , '/' , $real_path);
//D:/sina
$basepath = str_replace($path, "", $real_path);
//处理打包逻辑
$processor = new JSCombineProcessor($basepath , $path , $pre);
//获取文件内容
$fileContent = $processor -> getContent();
echo $fileContent;
?>
<?php
class JSCombineProcessor {
public $basePath;
public $relativePath;
public $prePath;
public $resultArr;
public $map;
public static function getOnlineSource($path) {
$api = "http://js.wcdn.cn".$path;
header('Location:'.$api);
/*
$api = "http://js.t.sinajs.cn".$path;
$host_ip = '211.101.171.217'; //ip地址
$dns_info = dns_get_record('js.t.sinajs.cn' , DNS_A);
if(count($dns_info) >= 1) {
$host_ip = $dns_info[0]['ip'];
}
$url_info = parse_url($api);
$api = str_replace($url_info['host'], $host_ip, $api); // 将域名替换成ip地址,指定到此ip地址下运行
$ch = curl_init($api);
curl_setopt($ch, CURLOPT_URL, $api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_host = array("Host:{$url_info['host']}"); //绑定域名到此ip地址上
curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_host); // 传送头信息
$result = curl_exec($ch);
$content_type = '';
// Check if any error occured
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);
$content_type = $info['content_type'];
header('Content-Type:'.$content_type);
}
echo $result;
// Close handle
curl_close($ch);
*/
}
public function __construct($basePath , $relativePath , $prePath) {
$this->basePath = $basePath;
$this->relativePath = $relativePath;
$this->prePath = $basePath.$prePath;
$this->resultArr = array();
$this->map = array();
}
public function checkFileBom($path) {
$chars = array(239,187,191);
$lines = file($path);
$bom = false;
if(count($lines) >= 1) {
$line = $lines[0] ;
if(strlen($line) >= 3) {
$bom = true;
for($i = 0 ; $i < 3 ; $i++) {
if(ord($line[$i]) != $chars[$i]) {
$bom = false;
break;
}
}
}
}
return $bom;
}
public function getContent() {
$entry = $this->basePath.$this->relativePath;
$this->processOneFile($entry);
return implode('',$this->resultArr);
}
public function processOneFile($filePath , $mapkey=false) {
$real_path = realpath($filePath);
if($real_path == false && $mapkey) {
$this->map[$mapkey] = 1;
return;
}
$isutf8bom = $this->checkFileBom($filePath);
if($isutf8bom) {
echo "alert('文件:".$filePath." 有utf8 bom 头,请修改')";
exit;
}
$list = file($filePath);
foreach($list as $line) {
preg_match ( '/^\s*\$import\s*\(\s*([\'"])\s*(.+)\s*\1\s*\).*$/i', $line, $aMatch );
if($aMatch) {
$namespace = $aMatch[2];
$replace = str_replace(".", "/", $namespace);
$entry = $this->prePath.$replace.".js";
if(!array_key_exists($namespace, $this->map)) {
$this->map[$namespace] = 1;
$this->processOneFile($entry , $namespace);
}
} else {
$this->resultArr[] = $line;
}
}
}
}
?>
分享到:
相关推荐
js读写本地文件js读写本地文件js读写本地文件js读写本地文件js读写本地文件
js实现的读写文件,文件放在的c:\12.txt里
js读取xml文件并获取文件内容
把文件资源打包进MFC的exe文件中,运行时进行加载,然后读取文件中的文本内容或者二进制内容 内含应用例程:1.把一个对象存为二进制文件,加载文件后恢复原对象 2.生成文本,加载资源中的文本文件,获取文本中的字符...
在web应用中,免不了把图片文件上传到服务器,当然途径不知一种。但是为了使后台接收上传文件的方法既使用网页上传,又适应桌面应用程序上传,方法的参数设置成两个,...本资料介绍的就是利用js把文件读取到字节数组。
在ie下可以读取任意盘的文件夹和文件,目前只兼容IE6+的浏览器 只能本地运行。 如果放到服务器上 js 文件将会报错automation 服务器不能创建对象 解决方案:点击“开始→运行”并输入“regsvr32 scrrun.dll”
那就请跟我来,本文将详细描述如何使用Javascript语言进行文件操作。 一、功能实现核心:FileSystemObject 对象 其实,要在Javascript中实现文件操作功能,主要就是依靠FileSystemobject对象。在详细介绍...
读取文件操作读取文件操作读取文件操作读取文件操作读取文件操作读取文件操作读取文件操作读取文件操作读取文件操作读取文件操作读取文件操作
一个简单的读取打包文件的类,可以将文件夹打包后读取打包文件的数据
php读写json文件php读写json文件php读写json文件php读写json文件
Eclipse打包成JAR包读取外部JAR包和外部配置文件 Eclipse 打包 jar 外部JAR 外部配置文件
js读取properties文件,很好用的。js读取properties文件,很好用的。js读取properties文件,很好用的。js读取properties文件,很好用的。
js 操作xml 文件 读取xml文件 js 操作xml 文件 读取xml文件
主要介绍了js读取csv文件并使用json显示出来,需要的朋友可以参考下
用html+javascript读出写入txt文件
在前台页面调用javascript,读写XML文件
前端Javascript+Html5+后端PHP分块上传文件,PHP分块上传大文件,该项目可以正常运行,入口为index.html,需要正确配置fileDir的读写权限 目前有测试过上传1.5G左右的没有问题(未测试更大的文件),理论上更大的...
在开发javascript插件的过程中,我们有时候需要获取当前JS文件的路径,用于自动加载一些图片、CSS等外部资源,但是javascript文件中并没有像PHP那样的__FILE__常量来供我们取得当前文件路径
Javascript读取本地的.txt文件