PHP: Get all files and folders from a directory (folder) PHP: ดูไฟล์และโฟลเดอร์ทั้งหมดจาก directory (โฟลเดอร์)
Posted on 16. โพสต์ใน 16. Jun, 2009 by Dragos in Coding , PHP มิ.ย., 2,009 โดย Dragos ใน การเข้ารหัส, PHP
To get all files and folders from a directory (folder) I found scandir to be the perfect solution. เพื่อรับไฟล์และโฟลเดอร์ทั้งหมดจาก directory (โฟลเดอร์) พบ scandir ให้เป็นโซลูชั่นที่สมบูรณ์แบบ.
scandir scans a directory and returns an array containing all files and directories under the parent directory we're looking in. scandir สแกนสมุดและผลตอบแทนที่แถวที่มีไฟล์และไดเรกทอรีภายใต้ไดเรกทอรีหลักที่เรากำลังมองหาระบบ
The code below will try to remove a directory, if the element is a directory or delete a file, if respectively the element is a file. โค้ดด้านล่างจะพยายามลบไดเรกทอรีหากองค์ประกอบเป็นไดเรกทอรีหรือลบไฟล์ถ้าตามลำดับองค์ประกอบเป็นไฟล์.
$lookin='./home/folder'; บ้าน $ lookin = '. / / โฟลเดอร์'; $elements=scandir($lookin); องค์ประกอบ $ = scandir ($ lookin) foreach($elements as $singleEl) { องค์ประกอบ ($ foreach เป็น $ singleEl) ( if(is_dir($lookin.'/'.$singleEl)) rmdir($lookin.'/'.$singleEl); ถ้า (is_dir ($ lookin .'/'.$ singleEl) rmdir) ($ lookin .'/'.$ singleEl) else อื่นๆ unlink($lookin.'/'.$singleEl); ยกเลิกการเชื่อมโยง ($ lookin .'/'.$ singleEl) } )
Related posts: บทความที่เกี่ยวข้อง:
- Apache & ModRewrite: How to easily deny access to a folder with htaccess Apache และ ModRewrite: วิธีง่ายปฏิเสธการเข้าถึงโฟลเดอร์ที่มี htaccess
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: วิธีการรับดัชนี (ตำแหน่งภายในกลุ่ม) ของวัตถุด้วย jQuery?
- JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: ฉันจะหาคุณสมบัติทั้งหมดสำหรับทุกองค์ประกอบ HTML ที่ไหน
- PHP: How to get creation time of file with PHP on Linux machines PHP: การได้เวลาสร้างไฟล์ด้วย PHP ในเครื่อง Linux
- Wordpress: Best SEO iTranslator for Wordpress, get free traffic from fully automated plugin script Wordpress: iTranslator SEO ที่ดีที่สุดสำหรับ Wordpress รับการเข้าชมฟรีจากสคริปต์ปลั๊กอินอัตโนมัติอย่างเต็มที่












































