Functions Used:
http://www.php.net/opendir
http://www.php.net/readdir
http://www.php.net/closedir
http://www.php.net/in-array
http://www.php.net/str-repeat
http://www.php.net/is-dir

Read Contents of a Directory With PHP

PHP Source was on www.codingforums.com

This function will read the full structure of a directory. It's recursive because it doesn't stop with the one directory, it just keeps going through all of the directories in the folder you specify. The CSS has been added to show how you can still use it on a PHP page

Example Calls:
getDirectory( "." );
// Get the current directory

getDirectory( "./files/includes" );
// Get contents of the "files/includes" folder

Directory Contents (you get them when you run the function) Are Shown Here:

CSS
     tutorial.css
     tutNav.css
     header.css
     mm_spa.css
scripts
     xmlNavTutorial.js
     tutNavA.js
     tutNav.js
     startTime.js
customerEnquiryToTable.php
bookDisplayCompleteInfo.php
sourceCode
     codeDropCustomersTable.html
     codePopulateCustomers.html
     codeFileAppend.php
     codePlaySoundTrack.php
     codeCreateCustomersTable.html
     codejazzedUpCustomerFormInputEnquiry.php
     codeCustomerEnquiryToTable.php
     codeStartTimeJavascript.html
     codePlayYouTube.php
     codeCustomerFormInputEnquiry.php
     codeNASABrowserDetect.html
     codeQueryCustomersToTable.html
     codeSelectResult.html
     codeJazzedUpProcessingCustomerFormInputEnquiry.php
     codeDateTimeScriptOnCPWWW888.php
     error_log
     codeFormCustomerEnquiry.php
     codePhpCaseStatementWithDefault.html
     codedeleteStudent Form.html
     codeNewStudent Form.html
     convertToSourceCode.html
     codeSupplementaryStartTimeJavascript.html
     convertToSourceCode_a.html
     codeBookCatalogEnquiryPaginated.php
     codeGetTotalFromMySQLTable.php
     codeTizagArtSupplyForm.html
     codeUpdateStudentTableFromForm.html
     codeMicrosoftAccessTableViaDotNet.php
     codeRead_text_to_array.html
     codeMicrosoftExcelinPhp.php
     codeSelect.html
     codeDeleteStudentFromForm.html
     codeMailToWWW_Classl.html
     codeFileCreate.php
     codeTrySendMail.html
     codePhpCaseStatement.html
     codeInsertRecordInDatabase.html
     codePickMinimumFromMySQLTable.php
     codeMicrosoftAccessTableinPhp.php
     codeBookCatalogEnquiry.php
     codePickMaximumFromMySQLTable.php
     codeClassCSSButtonsExercise.php
     codePickAverageFromMySQLTable.php
     codeConnectToDatabase.html
     codeDeleteCustomersRecords.html
     codePhilipsCSSExerciseSolution.php
     coderead_text.html
     codeReadSample.php
     codeProcessTizagArtSupply.html
     codeSimulatedFormCustomerEnquiry.php
phpMenu.html
read_text.php
testPosition.html
sampleMenuDeveloper.php
tryDeleteRecordFromDatabase.php
createCustomersTable.php
sampleMenuDeveloper_b.php
ssShopCart.php
bookCatalogEnquiryPaginated.php
phpCaseStatement.php
addStudent.html
secondXML.html
data
     _notes
         dwsync.xml
     names.txt
     sampleFile.txt
     cd_catalog.xml
     sampleFile1.txt
     catalog.txt
     note.xml
     ssSC_pageList.xml
tryInsertRecordInDatabase.php
includes
     dateStuff.php
     tutTitle.php
     header.php
     navButtons.php
     codeBox.php
dropCustomersTable.php
example.php
bookCatalogEnquiry.php
tizagArtSupplyForm.php
pickMinimumFromMySQLTable.php
deleteCustomersRecords.php
Excel
     reader.php
readSampleFile.php
images
     sdws.png
     tiger_mowmow.jpg
     chLogoDouble.png
     mm_bg_red.gif
     cat_helmet.jpg
     redRightArrow.jpg
     mm_spa_photo2.jpg
     redLeftArrow.jpg
     mm_bullet_yellow.gif
     mm_spacer.gif
     dipstic.png
     165303main_image_feature_719_ys_4.jpg
     mm_spa.css
     rightArrow.jpg
bookCatalogEnquiryLinksPaginated.php
updateStudentTableFromForm.php
tips
     UploadFromExcel.php
     uploadFromExcel.php
newStudentForm.html
tryConnectToDatabase.php
evolvingWebDesigner.php
sampleTutorial
     mm_spa_photo1.jpg
     testPage2.html
     testPage.html
     mm_bg_red.gif
     XML
         tutNavList.xml
     sampleTutorialPage.php
     mm_spa_photo2.jpg
     mm_bullet_yellow.gif
     TutorialPage1.php
     sampleTutorialPage3.html
     mm_spacer.gif
     mm_spa.css
     testPage.php
     sampleTutorialPage2.php
tryMusic.php
mailToWWW_ClassWithIP.php
tryFileWrite.php
error_log
jxlrwtest.xls
sampleMenuDeveloper_d.php
sampleMenuDeveloper_c.php
jazzedUpCustomerFormInputEnquiry.php
fistXML.html
firstXML.html
ssShopCartSeparatePages.php
music
     Beethoven's Symphony No. 9 (Scherzo).wma
deleteStudentForm.html
selectresult.php
select.htm
CSSNotes
     Quirks of Internet Explorer.pdf
     Quirks of Internet Explorer.doc
phpCaseStatementWith Default.php
navTut.php
junkStuff
     tester9.html
     tester1.html
     tester20.html
     tester7.html
     miniDivTest.html
     tester4.html
     tester3.html
     tester10.html
     tester8.html
     tester2.html
     tester12.html
     tester6.html
     tester13.html
     tester5.html
     containerDivTest.html
     tester11.html
deleteStudentFromForm.php
ssSCTutorial
     cart2.php
     catalog4.php
     catalog6.php
     sessions3.php
     cart3.php
     catalog7.php
     sessions2.php
     catalogLast.php
     catalog5.php
     sessions.php
     catalog9.php
     cart4.php
     catalog5a.php
     ssSC_index.php
     catalog3.php
     cart1.php
     catalog1.php
     catalog8.php
     catalog2.php
     sessions4.php
     Programming PHP Chapter 5 Arrays.mht
updateStudentData.php
read_text_to_array.php
fileCreate.php
pickMaximumFromMySQLTable.php
_jazzedUp.php
mailToWWW_Class.php
authorEnquiryBySurname.php
cssTutorial
     images
         general
             logo_enlighten.gif
         headers
             ad
                 headers
             about.jpg
         nav
             portfolio.gif
             contact.gif
             about.gif
             services.gif
     css
         master.css
     index.html
     about.html
XMLFiles
     phpinc_pageList.xml
     ssSC_pageList.xml
playYouTube.php
tryAppendData_2.php
queryCustomersToTable.php
customerFormInputEnquiry.php
thirdPage.html
assignments
     On Line Book Store Catalog System.doc
formCustomerEnquiry.php
directory_lister_a.php
ssShopDisplayCart.php
authorEnquiry.php
customerFormInputEnquiry_a.php
Templates
     tutorial.dwt
     tutorial.html
getTotalFromMySQLTable.php
phpMenu.php
cssStuff
     codeericMeyerCssReset.php
     class_exercise.html
     TMPfxk633awhq.html
     Philips_Solution.html
navTut.html
fileAppend.php
QueryCustomersToTable.php
index.php
queryWWW_Class.php
authorEnquiryProcessor.php
authorLinksEnquiryProcessor.php
QueryDatabaseToTable.php
sampleMenuDeveloper_f.php
populateCustomers.php
pickAverageFromMySQLTable.php
tryQueryOnDatabase.php
phpIncTut
     phpIncludesTut3.php
     phpIncludesTut.php
     phpIncludesTut2.php
processTizagArtSupply.php
updateStudent.html
authorsLinksEnquiryPaginated.php
ipAddressTest.php
navXML.html
trySendMail.php
tutMenuXML.php
sampleMenuDeveloper_e.php
playSoundTrack.php
authorSurnameEnquiryProcessor.php
note.xml
sessions.html
tryWriteData.php
topLevelSample.html
sampleMenuDeveloper_a.php
authorsEnquiryPaginated.php
tryAppendData.php
wanidaDotComShopCart_2.php
wanidaDotComShopCart.php