自用PHP在线Access转html表格小功能(快速预览access)

自用PHP在线Access转html表格小功能(支持大文件上传,得到一表一文件)
本工具用于Access数据表转html下载供预览,特别适合各类程序员。
开发环境(可能只支持)Windows IIS PHP5.4 其他系统或新版本都不支持

 请保留版权信息
//开发环境(可能只支持)Windows IIS PHP5.4 其他系统或新版本都不支持
//不定期更新详情关注:https://Access2html.96448.cn/
*/

/*
广告:易名一口价出售珍藏域名
网址:https://135634.shop.ename.com/
域名	简介	类型	注册时间
yichabiao.cn	易查表(格)	易名一口价	2020/4/20
maLide.cn	码立得	易名一口价	2020/4/22
echafen.cn		易名一口价	2016/8/29
11170.cn	5数客服米	易名一口价	2012/9/5
aiyaha.com	哎呀哈	易名一口价	2014/10/9
mabida.com		易名一口价	2015/4/5
saoLide.cn	扫(码)立得	易名一口价	2021/4/21
Lidehui.cn	立得惠	易名一口价	2021/6/4
96448.cn	谐音:就来试试吧	易名一口价	2011/9/28
souLide.cn	搜立得	易名一口价	2020/4/9
*/

//error_reporting(0);
$biaoti = "自用PHP在线Access转html表格小功能(Access2html)";
$dlimi = "1"; //分片大小MB
$zlimi = "10"; //总文件限制MB
$upext = ".mdb|.asa";//上传格式限定;|隔开
$upexe = str_replace("|",",",$upext);//上传格式限定
$tima = date("YmdHis");
//以下只为获得功能页面网址用于上传文件网址拼接
$iport = $_SERVER['SERVER_PORT'];
$indes = $_SERVER['SCRIPT_NAME'];
$inder = dirname($_SERVER['PHP_SELF']);
$ihost = $_SERVER['HTTP_HOST'];
if(stristr("-443-","-$iport-")){
$ihosts = "https://$ihost{$inder}";
}elseif(stristr("-80-","-$iport-")){
$ihosts = "http://$ihost{$inder}";
}else{
$ihosts = "http://$ihost:{$iport}{$inder}";
}
/*
免费查询系统下载: http://96448.cn
php+mysql系列查询系统 http://sql.chalide.cn
php+Txt系列查询系统 http://txt.chalide.cn
一站式万用查询平台1:http://chalide.com
一站式万用查询平台2:http://add.12391.net
*/
$css = "";
$css .= "";
function jsonMsg($code,$msg,$url=''){
  $arr = []; $arr['code'] = $code; $arr['msg'] = $msg; $arr['url'] = $url;
  header('Content-type: application/json');
  exit(json_encode($arr));
}
function heFile($filebath,$bnum)  {
  $wfp = fopen($filebath, $bnum == 1 ? "wb" : "ab");
  $rfp = fopen($_FILES['file']['tmp_name'], "rb");
  $bool = false;
  while ($buff = fread($rfp, 4096)) {
  if(!$bool = fwrite($wfp, $buff)) return $bool;
  }
  fclose($wfp);
  fclose($rfp);
  return $bool;
}
function characet($data){
  if(!empty($data) ){    
    $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;   
    if( $fileType != 'UTF-8'){   
      $data = mb_convert_encoding($data ,'utf-8' , $fileType);   
    }   
  }   
  return $data;    
}
//如果含html则替换<>'"
function reps($stext){
$stext = str_replace(array("<", ">",), array("<", ">"), $stext);
$stext = str_replace(array("\r\n","\r","\n"),"
",$stext); return characet($stext); } function db2zip($zipfile,$dbsname,$tima){ global $css; if(!file_exists($dbsname)){ exit("存储路径出错!"); } $shuoy = "

$dbsname

"; $zip = new ZipArchive; $res = $zip->open($zipfile, ZipArchive::CREATE); if ($res === TRUE) { //当前读取无密码数据文件 $cstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ={$dbsname}"; $conn = @odbc_connect($cstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); $result = odbc_tables($conn); $table=[]; while (odbc_fetch_row($result)){ if(odbc_result($result,"TABLE_TYPE")=="TABLE") $table[] =odbc_result($result,"TABLE_NAME"); } odbc_close($conn); if(count($table)<1){ exit("读取失败:空白数据表!");} foreach($table as $rowname){ $rawhtml = showbiao($dbsname,$rowname); $zip->addFromString("$rowname.html", "$css".$rawhtml); $shuoy .= "

$rowname

\r\n"; } //$zip->addFile("chalide.zip","chalide.zip"); $zip->addFromString("_ReadMe.txt", $shuoy); $zip->close(); } else { exit("fail zip:ZipArchive failure"); } } function showbiao($dbsname,$rewname){ $cstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ={$dbsname}"; $conn = @odbc_connect($cstr,"","",SQL_CUR_USE_ODBC ) or die ("数据库连接错误!"); $query = @odbc_do($conn, "select * from [{$rewname}]"); $fieldcount = odbc_num_fields($query); $h .= " \r\n"; $h .= ""; $h .= ''; for( $i=0; $i<$fieldcount; $i++){ $info = reps(odbc_field_name($query,$i+1)); $h .= ""; } $h .= ''; while ($row = odbc_fetch_row($query)){ $iy++; $h .= ''; for( $i=0; $i<$fieldcount; $i++){ $info = reps(odbc_result($query,$i+1)); $h .= ""; } $h .= ''; } if($iy<1){ $h .= ""; } $h .= '
表:$rewname ({$fieldcount}列)
$info
$info
没有查询到相关信息哦
'; odbc_close($conn); return $h; } if($_FILES['file']['tmp_name'] && $_POST['blob_num']){ $filex = $_FILES['file']; $filen = (isset($_POST['file_name']))?Trim($_POST['file_name']):''; $timen = (isset($_POST['nowYmd']))?Trim($_POST['nowYmd']):date("YmdHis").$uniqid(); if ($filex["error"] > 0){ $fer = []; $ercode = $filex["error"]; $fer["1"] = '上传的文件超过了upload_max_filesize选项限制的值'; $fer["2"] = '上传文件的大小超过了表单MAX_FILE_SIZE选项指定的值'; $fer["3"] = '上传异常,文件只有部分被上传'; $fer["4"] = '文件空白或者说没有文件被上传'; $fer["6"] = '上传的临时文件丢失'; $fer["7"] = '文件写入失败建议检查文件夹读写权限'; if($fer[$ercode]){ jsonMsg("0","Error 00".$ercode.":".$fer[$ercode]); }else{ jsonMsg("0","Error 00".$ercode.":未知上传错误!"); } }else{ $info = pathinfo($filen); $tape = strtolower($info['extension']); if(!stristr("|$upext|","|.{$tape}|")){ jsonMsg("0","Error 010,后缀.{$tape}不支持!");} if($filex["size"]>$dlimi*1024*1024){ jsonMsg("0","Error 011,单片文件大小超{$dlimi}MB!");} if($_POST["filesize"]>$zlimi*1024*1024){ jsonMsg("0","Error 012,文件总大小超{$zlimi}MB!");} $filepath = "./upload/"; //存储路径 if(!is_dir($filepath)) { @mkdir($filepath,0755,true);} if(!is_dir($filepath)) { jsonMsg("0","Error 015,文件夹失败{$filepath}!");} $filebath = $filepath . "$timen.$tape"; $bnum = (isset($_POST['blob_num']))?addslashes($_POST['blob_num']):''; $tnum = (isset($_POST['total_blob_num']))?addslashes($_POST['total_blob_num']):''; $fnum = (isset($_POST['filesize']))?addslashes($_POST['filesize']):'0'; if(!is_numeric($bnum) || !is_numeric($tnum)) jsonMsg("0","Error 0161,分片参数得数字!"); if(!is_numeric($fnum) ) jsonMsg("0","Error 0162,参数filesize得数字!"); $urlx = $ihosts.Ltrim($filebath,".").".zip"; if("@$bnum" == "@1" && "@$tnum"=="@1"){ move_uploaded_file($_FILES['file']['tmp_name'],$filebath);//直接更名保存 $fsize=filesize($filebath); $fzip = db2zip($filebath.".zip",$filebath,$tima); if($fnum==$fsize) jsonMsg("2","OK",$urlx); else jsonMsg("2","可能异常!",$urlx); }elseif($bnum<$tnum && $tnum>1){ heFile($filebath,$bnum); jsonMsg("1","waiting $bnum/$tnum !"); }elseif($bnum==$tnum && $tnum>1){ heFile($filebath,$bnum); $fsize=filesize($filebath); $fzip = db2zip($filebath.".zip",$filebath,$tima); if($fnum==$fsize) jsonMsg("2","OK@$filebath",$urlx); else jsonMsg("2","可能异常!",$urlx); }else{ jsonMsg("0","Error 017,分片异常:$bnum / $tnum!"); } } } ?> <?php echo "$biaoti"; ?>

自用在线Access转html表格小功能(支持大文件上传,得到一表一文件)

说明:限制大小Mb;支持格式上传!

作用:上传Access数据得到各表html表格数据!

'; ?> 环境:可能仅支持WIN PHP5.4/Linux不支持/高版本PHP不支持!

'; ?>

你可能感兴趣的:(php)