跳到主要內容

發表文章

目前顯示的是 2023的文章

PHP + CI4 的 PhpSpreadsheet 的處理

0、需要用到的 Library use \PhpOffice\PhpSpreadsheet\Spreadsheet; use \PhpOffice\PhpSpreadsheet\Writer\Xlsx; use \PhpOffice\PhpSpreadsheet\Reader\Xlsx; use \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; 參考資料: Welcome to PhpSpreadsheet's documentation - PhpSpreadsheet Documentation  1、上傳 excel 檔案並讀取內容 //處理上傳 try {             $thefile = $this->request->getFile('theuploadfile'); } catch (\Exception $e) { echo $e; exit; } try { $path = $thefile->store(); } catch (\Exception $e) { echo $e; exit; } //確認檔案格式並讀取內容 $filename = WRITEPATH . 'uploads/' . $path; $fileext = ucfirst($thefile->getClientExtension()); if (in_array($fileext, array('Xls', 'Xlsx'))) { $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($fileext); $spreadsheet = $reader->load($filename); $sheet = $spreadsheet->getSheet(0); $data = $sheet->getCell('A1')->getValue(); } 2、產生 Excel 檔案 / /生成試算表並設定格式 $spreadsheet = new Spreadsheet(); $spreadsh

幾個 Linux command

搜尋 n 天前有修改的檔案 find -mtime -n 刪除 n 天前建立的檔案 find -mtime +n -exec rm {} \; 以檔名規則搜尋檔案並刪除 find . -name "abc*" -delete 同步排除某些資料夾或檔案 rsync -r -q --exclude "dir*" --exclude "file*.txt" [source] [distination]

幾個網頁排版技巧

  1、首行縮排2字元 中文文章會習慣每段的首行縮排2字元 CSS設定:text-indent: 2em 2、利用 Web font loader 動態載入網路字型 JS: <script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script> <script>      WebFont.load({           google: {   families: ['Noto Sans TC','Droid Sans'] }   }); </script> 參考資料: 網路字型載入工具  |  Google Fonts  |  Google Developers typekit/webfontloader: Web Font Loader gives you added control when using linked fonts via @font-face. (github.com) 网页字体优化之字体异步加载 | Blog @ GIUEM Web字体载入利器(Web Font Loader)使用详解(Web字体加载缓慢解决办法)_web加载字体_lt_1111的博客-CSDN博客 Web字体载入利器-->Web Font Loader - w3ctech 3、常用CDN jQuery CDN Google Hosted Libraries  |  Google Developers 4、改善字型 render body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; font-smoothing: antialiased; }

Mysql 新增使用者

 單純新增使用者 create user 'username'@'localhost' identified by 'password'; 新增權限使用者 grant all privileges on *.* to 'username'@'localhost' identified by 'password' with grant option;

Ubuntu 22.04 安裝PHP 7.4

目前最新的 Ubuntu LTS 是 22.04 版,其預設的套件庫 PHP 是 8.1 版本。 相較於 Ubuntu 20.04 用的是 PHP7.4,PHP8.1對於變數的宣告和陣列的 KEY 值有很嚴格的限制,未事前宣告的變數或陣列 KEY值就會報錯。如果是小一點的程式,在報錯的地方再針對變數和KEY 多做一個判斷可以解決;但是大一點的程式就很傷腦筋了。 網路上有提供新增套件庫,將原本的 PHP8.1 降級成 PHP7.4 的方法,以前設定時還蠻順利的,但是最近新設定一台虛擬主機時,欲一直遇到 python 的問題,最後利用手動增加套件庫的方式才解決這個問題。 參考資料: https://askubuntu.com/questions/1393381/unable-to-add-ondrej-repository-apt-in-ubuntu-20-04 1、在 /etc/apt/source.d 中新增 ondrej-ubuntu-php-jammy.list 2、在 ondrej-ubuntu-php-jammy.list 中新增: deb https://ppa.launchpadcontent.net/ondrej/php/ubuntu/ jammy main # deb-src https://ppa.launchpadcontent.net/ondrej/php/ubuntu/ jammy main 3、匯入所需的金鑰: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4f4ea0aae5267a6c  然後再作 apt update 及 apt install php7.4-fpm 及 php7.4 的相關套件即可。 設定系統主要啟用 PHP 版本 sudo update-alternatives --config php