PHP: Get all files and folders from a directory (folder) PHP: קבל את כל הקבצים והתיקיות בספרייה (תיקייה)
Posted on 16. פורסם ב 16. Jun, 2009 by Dragos in Coding , PHP יוני, 2009 על ידי Dragos ב וקידוד, PHP
To get all files and folders from a directory (folder) I found scandir to be the perfect solution. כדי לקבל את כל הקבצים והתיקיות בספרייה (תיקייה) מצאתי 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'; הביתה מסתכל $ = ". / / תיקייה"; $elements=scandir($lookin); אלמנטים $ = scandir ($ מחפש); foreach($elements as $singleEl) { אלמנטים foreach ($ $ כמו singleEl) ( if(is_dir($lookin.'/'.$singleEl)) rmdir($lookin.'/'.$singleEl); אם (is_dir ($ לחפש .'/'.$ singleEl)) rmdir ($ לחפש .'/'.$ singleEl); else אחר unlink($lookin.'/'.$singleEl); unlink ($ לחפש .'/'.$ singleEl); } )
Related posts: הודעות קשורות:
- Apache & ModRewrite: How to easily deny access to a folder with htaccess אפאצ 'י & 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 על מכונות לינוקס
- Wordpress: Best SEO iTranslator for Wordpress, get free traffic from fully automated plugin script וורדפרס: Best iTranslator SEO עבור וורדפרס, מקבלים תנועה חופשית סקריפט תוסף אוטומטי לחלוטין












































