This is a translated page. The original can be found here: http://iwebdevel.com/2009/06/16/php-get-all-files-and-folders-from-a-directory-folder/
UPDATES VIA RSS | Email การปรับปรุงผ่านทาง RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / PHP / PHP: Get all files and folde… บ้าน / รหัส / PHP / PHP: ดูไฟล์ทั้งหมดและ folde ...

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) 
 } ) 
Translate this post แปลบทความนี้


Related posts: บทความที่เกี่ยวข้อง:

  1. Apache & ModRewrite: How to easily deny access to a folder with htaccess Apache และ ModRewrite: วิธีง่ายปฏิเสธการเข้าถึงโฟลเดอร์ที่มี htaccess
  2. JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: วิธีการรับดัชนี (ตำแหน่งภายในกลุ่ม) ของวัตถุด้วย jQuery?
  3. JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: ฉันจะหาคุณสมบัติทั้งหมดสำหรับทุกองค์ประกอบ HTML ที่ไหน
  4. PHP: How to get creation time of file with PHP on Linux machines PHP: การได้เวลาสร้างไฟล์ด้วย PHP ในเครื่อง Linux
  5. Wordpress: Best SEO iTranslator for Wordpress, get free traffic from fully automated plugin script Wordpress: iTranslator SEO ที่ดีที่สุดสำหรับ Wordpress รับการเข้าชมฟรีจากสคริปต์ปลั๊กอินอัตโนมัติอย่างเต็มที่

    blog comments powered by Disqus บล็อกความคิดเห็นขับเคลื่อนโดย Disqus