|
6 | 6 | session_start(); |
7 | 7 | $bg=2; |
8 | 8 | $step=20; |
9 | | -$version="3.16.0"; |
| 9 | +$version="3.16.1"; |
10 | 10 | $bbs=['False','True']; |
11 | 11 | $deny=['sqlite_sequence']; |
12 | 12 | $js=(file_exists('jquery.js')?"/jquery.js":"https://code.jquery.com/jquery-1.12.4.min.js"); |
@@ -353,13 +353,15 @@ public function imp_xml($fname,$fbody) { |
353 | 353 | } |
354 | 354 | public function imp_sqlite($fname,$fbody) { |
355 | 355 | $res=[]; |
356 | | - if(substr($fbody,0,15) !="SQLite format 3") $res[$fname]="No SQLite file"; |
| 356 | + if(substr($fbody,0,15) !="SQLite format 3") $res[$fname]="No sqlite file"; |
357 | 357 | $file=pathinfo($fname); |
358 | 358 | $new=$this->dir.$this->sanitize($file['filename']).$this->ext; |
| 359 | + if(!file_exists($new)) { |
359 | 360 | $sfile=fopen($new,"wb"); |
360 | 361 | if(!$sfile) $res[$fname]="Unable to create sqlite file"; |
361 | 362 | fwrite($sfile,$fbody); |
362 | 363 | fclose($sfile); |
| 364 | + } else $res[$fname]="File already exists"; |
363 | 365 | return $res; |
364 | 366 | } |
365 | 367 | public function tb_structure($tb,$fopt,$tab='') { |
@@ -1130,7 +1132,7 @@ public function getTables($db) { |
1130 | 1132 | $db=$ed->sg[1]; |
1131 | 1133 | $tb=$ed->sg[2]; |
1132 | 1134 | $ed->con->exec("DELETE FROM ".$tb); |
1133 | | - $ed->redir("5/$db",['ok'=>"Table is empty"]); |
| 1135 | + $ed->redir("20/$db/$tb",['ok'=>"Table is empty"]); |
1134 | 1136 | break; |
1135 | 1137 |
|
1136 | 1138 | case "26"://drop table |
@@ -1210,35 +1212,42 @@ public function getTables($db) { |
1210 | 1212 | } |
1211 | 1213 | if(@function_exists('gzopen')) { |
1212 | 1214 | preg_match("/^(.*)\.(sql|csv|json|xml|db|sqlite|tar)$/i",$fext[1],$ex); |
1213 | | - if($ex[2]!='tar') { |
1214 | 1215 | $gzfile=@gzopen($tmp,'rb'); |
1215 | 1216 | if(!$gzfile) $ed->redir("5/$db",['err'=>"Can't open GZ file"]); |
1216 | 1217 | $e=''; |
1217 | 1218 | while(!gzeof($gzfile)) { |
1218 | 1219 | $e.=gzgetc($gzfile); |
1219 | 1220 | } |
1220 | 1221 | gzclose($gzfile); |
1221 | | - } |
1222 | 1222 | if($ex[2]=='sql') $e=preg_split($rgex,$ed->utf($e),-1,PREG_SPLIT_NO_EMPTY); |
1223 | 1223 | elseif($ex[2]=='csv') $e=$ed->imp_csv($ex[1],$e); |
1224 | 1224 | elseif($ex[2]=='json') $e=$ed->imp_json($ex[1],$e); |
1225 | 1225 | elseif($ex[2]=='xml') $e=$ed->imp_xml($ex[1],$e); |
1226 | 1226 | elseif(in_array($ex[2],['db',substr($ed->ext,1)])) $lite[]=$ed->imp_sqlite($ex[1],$e); |
1227 | 1227 | elseif($ex[2]=='tar') { |
1228 | | - $e=[];$tmpTar=$ed->dir.'_tmp.tar'; |
1229 | | - file_put_contents($tmpTar, gzdecode(file_get_contents($tmp))); |
1230 | | - $pd=new PharData($tmpTar); |
1231 | | - foreach($pd as $en) { |
1232 | | - $fi=$en->getFilename(); |
| 1228 | + $fh=gzopen($tmp,'rb'); |
| 1229 | + $fsize=strlen($e); |
| 1230 | + $total=0;$e=[]; |
| 1231 | + while(false !== ($block=gzread($fh,512))) { |
| 1232 | + $total+=512; |
| 1233 | + $t=unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime",$block); |
| 1234 | + $file=['name'=>$t['name'],'mode'=>@octdec($t['mode']),'uid'=>@octdec($t['uid']),'size'=>@octdec($t['size']),'mtime'=>@octdec($t['mtime'])]; |
| 1235 | + $file['bytes']=($file['size'] + 511) & ~511; |
| 1236 | + if($file['bytes'] > 0) { |
| 1237 | + $block=gzread($fh,$file['bytes']); |
| 1238 | + $f_b=substr($block,0,$file['size']); |
| 1239 | + $fi=trim($file['name']); |
1233 | 1240 | preg_match("/^(.*)\.(sql|csv|json|xml|db|sqlite)$/i",$fi,$fx); |
1234 | | - $f_b=$en->getPathName(); |
1235 | 1241 | if($fx[2]=='sql') $e[]=preg_split($rgex,$ed->utf($f_b),-1,PREG_SPLIT_NO_EMPTY); |
1236 | 1242 | elseif($fx[2]=='csv') $e[]=$ed->imp_csv($fx[1],$f_b); |
1237 | 1243 | elseif($fx[2]=='json') $e[]=$ed->imp_json($fx[1],$f_b); |
1238 | 1244 | elseif($fx[2]=='xml') $e[]=$ed->imp_xml($fx[1],$f_b); |
1239 | | - elseif(in_array($fx[2],['db',substr($ed->ext,1)])) $lite[]=$ed->imp_sqlite($fx[1],file_get_contents($f_b)); |
| 1245 | + elseif(in_array($fx[2],['db',substr($ed->ext,1)])) $lite[]=$ed->imp_sqlite($fx[1],$f_b); |
| 1246 | + $total+=$file['bytes']; |
| 1247 | + } |
| 1248 | + if($total >= $fsize-1024) break; |
1240 | 1249 | } |
1241 | | - @unlink($tmpTar); |
| 1250 | + gzclose($fh); |
1242 | 1251 | if(!empty($e)) $e=call_user_func_array('array_merge',$e); |
1243 | 1252 | } |
1244 | 1253 | } else { |
|
0 commit comments