申明:在Linux下把excel數據導入到mysql數據庫中,這其實是很搞笑的一個勾當!幾近很少有法式員研究過這個問題吧?如斯反常的問題,估量我是第一個研究的!呵呵,完全是自找苦吃~~,可是今天完了這項太有挑戰性的工作!
先清理一下思緒先,~~
起首:需要把文件上傳到辦事器上
然後:讀取excel數據列顯示出來
然後:讓用戶選擇字段的對應關係
然後:提交數據,讀取字段的對應關係
最後:批量導入數據,刪除且自文件
一共是以上五步調!我們一步步剖析~~~
第一步:下載附件中的phpexcelparser4.rar ,這個文件是上傳excel盜辦事器上並以web情勢展現出來的!這個一般沒有問題的!問題是法式的做法是把表存為且自表而沒有真正留存下來,所以起首要更改法式代碼為

 

  1.  
  2. //uc轉換成html
  3. function uc2html($str) {
  4.    $ret = '';
  5.    for( $i=0; $i<strlen($str)/2; $i++ ) {
  6.        $charcode = ord($str[$i*2])+256*ord($str[$i*2+1]);
  7.        // $ret .= '&#'.$charcode;
  8.        if($charcode<127)
  9.          $ret .=chr($charcode);
  10.        else
  11.            $ret .= iconv("utf-8","utf-8",u2utf8($charcode));
  12.    }
  13.        return $ret;
  14. }
  15. //html轉成utf8
  16. function u2utf8($c) {
  17. $str="";
  18. if ($c < 0x80) {
  19.   $str.=$c;
  20. } else if ($c < 0x800) {
  21.   $str.=chr(0xC0 | $c>>6);
  22.   $str.=chr(0x80 | $c & 0x3F);
  23. } else if ($c < 0x10000) {
  24.   $str.=chr(0xE0 | $c>>12);
  25.   $str.=chr(0x80 | $c>>6 & 0x3F);
  26.   $str.=chr(0x80 | $c & 0x3F);
  27. } else if ($c < 0x200000) {
  28.   $str.=chr(0xF0 | $c>>18);
  29.   $str.=chr(0x80 | $c>>12 & 0x3F);
  30.   $str.=chr(0x80 | $c>>6 & 0x3F);
  31.   $str.=chr(0x80 | $c & 0x3F);
  32. }
  33. return $str;
  34. }
  35.  
  36. if (trim($_POST["cmd"])=="upload")
  37. {
  38. $err_corr = "Unsupported format or file corrupted";
  39. $excel_file_size;
  40. $excel_file = $_FILES['excel_file'];
  41. $uploadservername=$UploadAbsPath."tmpexcel/".$_FILES['excel_file']['name'];
  42. echo($uploadservername);
  43.      if (!is_writeable($UploadAbsPath."tmpexcel/"))
  44.      {
  45.      echo "目次不可寫!"; exit;
  46.      }
  47.      else
  48.      {
  49.      echo "目次可寫!";
  50.      }
  51. if (move_uploaded_file($_FILES['excel_file']['tmp_name'], $uploadservername))
  52. {
  53.     echo("上傳成功");
  54. }
  55. else
  56. {網頁設計
  57.     echo("上傳失敗");
  58. }
  59. $excel_file=$uploadservername;
  60. //if( $excel_file )
  61. //    $excel_file = $_FILES['excel_file']['tmp_name'];
  62.  
  63.  
  64. if( $excel_file == '' ) fatal("No file uploaded");
  65.  
  66.  
  67. $exc = new ExcelFileParser("debug.log", ABC_NO_LOG);//ABC_NO_LOG ABC_VAR_DUMP);
  68.     //echo($excel_file."|");
  69.    
  70. $style = $_POST['style'];
  71. if( $style == 'old' )
  72. {
  73.     $fh = @fopen ($excel_file,'rb');
  74.     if( !$fh ) fatal("No file uploaded");
  75.     if( filesize($excel_file)==0 ) fatal("No file uploaded");
  76.     $fc = fread( $fh, filesize($excel_file) );
  77.     @fclose($fh);
  78.     if( strlen($fc) < filesize($excel_file) )
  79.     fatal("Cannot read file");
  80.    
  81.     $time_start = getmicrotime();
  82.     $res = $exc->ParseFromString($fc);
  83.     $time_end = getmicrotime();
  84. }
  85. elseif( $style == 'segment' )
  86. {
  87.     $time_start = getmicrotime();
  88.     $res = $exc->ParseFromFile($excel_file);
  89.     $time_end = getmicrotime();
  90. }
  91.  
  92.  
  93. switch ($res) {
  94.     case 0: break;
  95.     case 1: fatal("Can't open file");
  96.     case 2: fatal("File too small to be an Excel file");
  97.     case 3: fatal("Error reading file header");
  98.     case 4: fatal("Error reading file");
  99.     case 5: fatal("This is not an Excel file or file stored in Excel < 5.0");
  100.     case 6: fatal("File corrupted");
  101.     case 7: fatal("No Excel data found in file");
  102.     case 8: fatal("Unsupported file version");
  103.  
  104.  
  105.     default:
  106.     fatal("Unknown error");
  107. }
  108.  
  109.  
  110. /*
  111. print '<pre>';
  112. print_r( $exc );
  113. print '</pre>';
  114. exit;
  115. */
  116.  
  117.  
  118. show_time();
  119.  
  120.  
  121. echo <<<LEG
  122. <b>Legend:</b><br><br>
  123. <form name='doform' action='' method='post'>
  124. <input type='hidden' name='action' value='do'>
  125. <input type='hidden' name='excel_file' value=$excel_file>
  126. <input type='hidden' name='style' value=$style>
  127. <table border=1 cellspacing=0 cellpadding=0>
  128. <tr><td>Data type</td><td>Description</td></tr>
  129. <tr><td class=empty>&nbsp;</td><td class=index>An empty cell</td></tr>
  130. <tr><td class=dt_string>ABCabc</td><td class=index>String</td></tr>
  131. <tr><td class=dt_int>12345</td><td class=index>Integer</td></tr>
  132. <tr><td class=dt_float>123.45</td><td class=index>Float</td></tr>
  133. <tr><td class=dt_date>123.45</td><td class=index>Date</td></tr>
  134. <table>
  135. <br><br>
  136.  
  137.  
  138. LEG;
  139. /*
  140. print "<pre>";
  141. print_r ($exc->worksheet);
  142. print_r($exc->sst);
  143. print "</pre>";
  144. */
  145.     for( $ws_num=0; $ws_num<count($exc->worksheet['name']); $ws_num++ )
  146.     {
  147.     print "<b>Worksheet: \"";
  148.     if( $exc->worksheet['unicode'][$ws_num] ) {
  149.     print uc2html($exc->worksheet['name'][$ws_num]);
  150.     } else
  151.     print $exc->worksheet['name'][$ws_num];
  152.  
  153.  
  154.     print "\"</b>";
  155.     $ws = $exc->worksheet['data'][$ws_num];
  156.  
  157.  
  158.     if( is_array($ws) &&
  159.          isset($ws['max_row']) && isset($ws['max_col']) ) {
  160.      echo "\n<br><br><table border=1 cellspacing=0 cellpadding=2>\n";
  161.  
  162.  
  163.      print "<tr><td>&nbsp;</td>\n";
  164.      for( $j=0; $j<=$ws['max_col']; $j++ ) {
  165.     print "<td class=index>&nbsp;";
  166.     if( $j>25 ) print chr((int)($j/26)+64);
  167.     //這裡要顯示一個下拉列表來顯示數據
  168.     //注意是循環數據<br />
  169.     echo("\n<select name='".$j."'>");
  170.     echo("\n<option value='0'>不選擇</option>");
  171.    echo("\n<option value='costomernum'>客戶編號</option>");
  172.    echo("\n<option value='name'>客戶姓名</option>");
  173.    echo("\n<option value='phone1'>德律風1</option>");
  174.    echo("\n<option value='phone2'>德律風2</option>");
  175.    echo("\n<option value='address1'>地址1</option>");
  176.    echo("\n<option value='address2'>地址2</option>");  
  177.    echo("\n<option value='company'>公司</option>");
  178.    echo("\n<option value='levelc'>職稱</option>");   
  179.    echo("\n<option value='ps'>備註</option>");
  180.    
  181.     echo("</select>");
  182.     print "</td>";
  183.      }
  184.  
  185.  
  186.      print "<tr><td>&nbsp;</td>\n";
  187.      for( $j=0; $j<=$ws['max_col']; $j++ ) {
  188.     print "<td class=index>&nbsp;";
  189.     if( $j>25 ) print chr((int)($j/26)+64);
  190.     print chr(($j % 26) + 65)."&nbsp;列名</td>";
  191.      }
  192.  
  193.  
  194.  
  195. //表頭輸出終了
  196.     if ($ws['max_row']>9)
  197.     {
  198.     $shownum=9;
  199.     }
  200.     else
  201.     {
  202.     $shownum=$ws['max_row'];//只輸出前10條數據
  203.     }
  204.      for( $i=0; $i<=$shownum; $i++ ) {
  205.      print "<tr><td class=index>".($i+1)."</td>\n";
  206.      if(isset($ws['cell'][$i]) && is_array($ws['cell'][$i]) ) {
  207.          for( $j=0; $j<=$ws['max_col']; $j++ ) {
  208.  
  209.  
  210.     if( ( is_array($ws['cell'][$i]) ) &&
  211.          ( isset($ws['cell'][$i][$j]) )
  212.          ){
  213.  
  214.  
  215.      // print cell data
  216.      print "<td class=\"";
  217.      $data = $ws['cell'][$i][$j];
  218.  
  219.  
  220.      $font = $ws['cell'][$i][$j]['font'];
  221.      $style = " style ='".ExcelFont::ExcelToCSS($exc->fonts[$font])."'";
  222.  
  223.  
  224.          switch ($data['type']) {
  225.     // string
  226.     case 0:
  227.         print "dt_string\"".$style.">";
  228.         $ind = $data['data'];
  229.         if( $exc->sst['unicode'][$ind] ) {
  230.         $s = uc2html($exc->sst['data'][$ind]);
  231.         } else
  232.         $s = $exc->sst['data'][$ind];
  233.         if( strlen(trim($s))==0 )
  234.         print "&nbsp;";
  235.         else
  236.         print $s;
  237.         break;
  238.     // integer number
  239.     case 1:
  240.         print "dt_int\"".$style.">&nbsp;";
  241.         print $data['data'];
  242.         break;
  243.     // float number
  244.     case 2:
  245.         print "dt_float\"".$style.">&nbsp;";
  246.         echo $data['data'];
  247.         break;
  248.     // date
  249.     case 3:
  250.         print "dt_date\"".$style.">&nbsp;";
  251.  
  252.  
  253.         $ret = $data[data];//str_replace ( " 00:00:00", "", gmdate("d-m-Y H:i:s",$exc->xls2tstamp($data[data])) );
  254.         echo ( $ret );
  255.         break;
  256.     default:
  257.         print "dt_unknown\"".$style."> &nbsp;";
  258.         break;
  259.          }
  260.      print "</td>\n";
  261.     } else {
  262.         print "<td class=empty>&nbsp;</td>\n";
  263.     }
  264.          }
  265.      } else {
  266.     // print an empty row
  267.     for( $j=0; $j<=$ws['max_col']; $j++ )
  268.         print "<td class=empty>&nbsp;</td>";
  269.     print "\n";
  270.      }
  271.      print "</tr>\n";
  272.      }
  273.  
  274.  
  275.      echo "</table><br>\n";
  276.     } else {
  277.     // emtpty worksheet
  278.     print "<b> - empty</b><br>\n";
  279.     }
  280.     print "<br>";
  281.  
  282.  
  283.     }
  284.     echo("<input type='submit' name='Submit' value='轉換' />");
  285.     echo("</form>");
  286. /*    print "Formats<br>";
  287.     foreach($exc->format as $value) {
  288.     printf("( %x )",array_search($value,$exc->format));
  289.     print htmlentities($value,ENT_QUOTES);
  290.     print "<br>";
  291.     }
  292.  
  293.  
  294.      print "XFs<br>";
  295.     for( $i=0;$i<count($exc->xf['format']);$i++) {
  296.     printf ("(%x)",$i);
  297.     printf (" format (%x) font (%x)",$exc->xf['format'][$i],$exc->xf['font'][$i]);
  298.  
  299.  
  300.     print "<br>";
  301.     }
  302. */
  303. }
文章標籤

marshabaopb 發表在 痞客邦 留言(0) 人氣()

網頁設計

ereg_replace()是個利用正則的replacestr_replace()
ereg_replace ( string $pattern , string $replacement , string $string ) : string
preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] ) : mixed
preg_replace()是今朝的保舉方案,必選參數3個,可選參數3個。根基上可以覆蓋 只不外是參數的具體用法分歧。返回值是根基上一致的。ereg_replace()
 
1.png

文章出處


文章標籤

marshabaopb 發表在 痞客邦 留言(0) 人氣()

6.png

先到打開伺服esp32網址(上方網址)
文章標籤

marshabaopb 發表在 痞客邦 留言(0) 人氣()

幾個星期LOG就300GB,每一個網站都這麼大

乾脆到WHM下把ERROR LOG關閉(否則三不五時要去刪檔案)
進入WHM->搜尋PHP->MutiPHP INI Editor->Editor Mode->選PHP7.4->log_errors = Off
whm002.png

文章出處: NetYea 網頁設計

之前遇到CPANEL發信給我


說磁碟空間不足


我心想4TB硬碟,沒幾個網站怎麼會空間不足


第一時候以為是網站被駭


到filezilla檢查事後發現是PHP7.4 的LOG超大

文章標籤

marshabaopb 發表在 痞客邦 留言(0) 人氣()

網頁設計
  1. <style>
  2.         .bg {
  3.             position: fixed;
  4.             top: 0;
  5.             left: 0;
  6.             bottom: 0;
  7.             right: 0;
  8.             z-index: -999;
  9.         }
  10.         .bg img {
  11.             min-height: 100%;
  12.             width: 100%;
  13.         }
  14.     </style>
複製代碼
文章標籤

marshabaopb 發表在 痞客邦 留言(0) 人氣()

網頁設計 

1.png

文章標籤

marshabaopb 發表在 痞客邦 留言(0) 人氣()

資料庫常常是有看沒有懂

圖解秒懂SQL說話

1.png

文章標籤

marshabaopb 發表在 痞客邦 留言(0) 人氣()

1.jpg
文章標籤

marshabaopb 發表在 痞客邦 留言(0) 人氣()


 

  1. rpm -ivh rp-pppoe-3.14-7.el8.lux.x86_64.rpm
文章標籤

marshabaopb 發表在 痞客邦 留言(0) 人氣()

網頁設計

 

在使用CSS的時候,用某些特效能讓網站更有活力,假如應用JQUERY又太甚複雜

不外今天作者看到某網站的運用不錯,於是就哄騙CSS也做了

可以看到下圖,滑鼠未移置圖片典範榜樣

1.png



用CSS寫以下代碼
 
  1. .chimga{
  2.     margin:10px;
  3.     width:100%;
  4.     height:100%;
  5.     box-sizing:border-box;
  6.     overflow:hidden;
  7.     display:block;
  8. }
  9. .chimga:hover img{
  10.     -moz-transform:scale(1.3) rotate(2deg);
  11.     -webkit-transform:scale(1.3) rotate(2deg);
  12.     -o-transform:scale(1.3) rotate(2deg);
  13.     -ms-transform:scale(1.3) rotate(2deg);
  14.     transform:scale(1.3) rotate(2deg);
  15. }
文章標籤

marshabaopb 發表在 痞客邦 留言(0) 人氣()