function openfile($filename,$check=1,$method="rb"){
$check && strpos($filename,'..')!==false && exit('What are you doing?');
if($handle=@fopen($filename,$method)){
flock($handle,LOCK_SH);
$filedata=@fread($handle,filesize($filename));
fclose($handle);
}
return $filedata;
}
//sql文件处理
function runquery($sql,$tablePreStr){
str_replace(chr(239).chr(187).chr(191),"",$sql);//去除BOM头
$sql = str_replace("\n", "", str_replace('isns_',$tablePreStr,$sql)); // 换行是无法用.号匹配的
preg_match_all("|(SET (.*?));|i",$sql, $set); //取出set语句
preg_match_all("|(DROP TABLE (.*?));|i",$sql, $drop); //取出drop语句
preg_match_all("|(CREATE TABLE (.*?));|i",$sql, $create); //取出create语句
preg_match_all("|(INSERT INTO (.*?)\));|i",$sql, $insert); //取出insert语句
$drop = empty($_POST['drop'])? 0:1;
sqlQuery($set[1],0,$tablePreStr);
sqlQuery($drop[1],$drop,$tablePreStr);
$tablenum = sqlQuery($create[1],$drop,$tablePreStr);
sqlQuery($insert[1],0,$tablePreStr);
return $tablenum;
}
阅读(406) | 评论(0) | 转发(0) |