PHP7 下檔案名稱太長導致 glob 回傳 false 的問題
很多時候在開發 PHP 的時候我們都會使用這個超級方便的 glob(*) 功能。簡單來說就是把一個資料夾或路徑內的檔案以 array 方式回傳的方法。然而,在最近的 ArOZ Online 測試伺服器更新之後發現了 File Explorer 在開啟某些資料夾時出現 PHP ERROR 的問題。後來經過一堆檢測之後發現原來是檔案名稱太長了,結果 glob 就直接回傳 false 。 原本的 listdir.php //Some code here for auth and var parsing if (file_exists($path) && is_dir($path)){ $filelist = glob($path . "/*"); //Other code } 要解決這個問題,我們需要把它改成使用 scandir ,然而由於 scandir 會多了很多代碼,為了節省處理能力,我們只在需要的時候使用 scandir 就好。結果新的 glob 部分就變成了這樣: //Some code here for auth and var parsing if (file_exists($path) && is_dir($path)){ $filelist = glob($path . "/*"); if ($filelist === false){ //Something went wrong while trying to list the directory using glob. Try scandir $scanResults = scandir($path); $filelist = []; $useAbnormalFilter = true; foreach ($scanResults as $fileObj){ if ($fileObj != "." && $fileObj != ".."){ array_push($filelist, $path . "/" . $fileObj); } } } //Other code } 就是這樣,File Explorer 的顯示就回復正常了。對,這都是 Windows 的錯。
How it works
IMUS Laboratory Product Development and Prototype Resale Welcome to IMUS Laboratory PD-PR web page. This post will explains how this page works. Basic work flow Tell us what you want to make, the more detail you give, the better the results and pricing accuracy. Tell us your target pricing or the amount you are willing to give for this prototype. MAKE SURE YOUR REQUEST IS "DESIGN SKETCH ONLY" or "PROTOTYPE READY" We will provide a rough pricing for your prototype (The final pricing may be greater or lower than the expected price) If you agree with the price, the project will be started. If you disagree with the price, you can try removing some functions or cancel the prototype request.        
Hello world!
This page was started on 12/9/2016.
目前第 5 頁,共有 5 頁