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
     vcwebcom.css
     mm_entertainment.css
templateDemo
     secondPage.html
     images
         pic16262.jpg
     Library
         leftMenu.lbi
     index.html
     thirdPage.html
     myFirstpage.html
golden888
     jeans
         ipn_main_handler.php
         editors
             htmlarea
                 dialog.js
                 htmlarea.css
                 examples
                     test.cgi
                     css.html
                     custom.css
                     index.html
                     2-areas.html
                     core.html
                     table-operations.html
                     full-page.html
                     2-areas.cgi
                     context-menu.html
                     spell-checker.html
                     fully-loaded.html
                 images
                     ed_indent_less.gif
                     ed_copy.gif
                     ed_blank.gif
                     ed_format_sub.gif
                     ed_help.gif
                     ed_save.gif
                     ed_align_justify.gif
                     ed_format_sup.gif
                     ed_list_bullet.gif
                     ed_list_num.gif
                     ed_paste.gif
                     ed_format_bold.gif
                     ed_right_to_left.gif
                     ed_about.gif
                     insert_table.gif
                     ed_charmap.gif
                     ed_delete.gif
                     ed_cut.gif
                     ed_undo.gif
                     ed_custom.gif
                     ed_show_border.gif
                     ed_html.gif
                     ed_splitcel.gif
                     ed_image.gif
                     fullscreen_maximize.gif
                     ed_format_underline.gif
                     ed_align_left.gif
                     ed_align_center.gif
                     ed_hr.gif
                     ed_color_bg.gif
                     ed_left_to_right.gif
                     ed_link.gif
                     ed_format_italic.gif
                     ed_redo.gif
                     ed_format_strike.gif
                     fullscreen_minimize.gif
                     ed_indent_more.gif
                     ed_align_right.gif
                     ed_color_fg.gif
                 license.txt
                 popups
                     insert_table.html
                     select_color.html
                     old-fullscreen.html
                     custom2.html
                     editor_help.html
                     link.html
                     old_insert_image.html
                     fullscreen.html
                     insert_image.html
                     popup.js
                     about.html
                     blank.html
                 release-notes.html
                 index.html
                 ChangeLog
                 lang
                     lv.js
                     hu.js
                     si.js
                     fr.js
                     de.js
                     fi.js
                     en.js
                     pt_br.js
                     nb.js
                     ja-utf8.js
                     he.js
                     nl.js
                     cz.js
                     da.js
                     lt.js
                     gb.js
                     pl.js
                     es.js
                     no.js
                     el.js
                     ja-euc.js
                     ja-sjis.js
                     it.js
                     se.js
                     vn.js
                     ee.js
                     ro.js
                     ja-jis.js
                     b5.js
                     ru.js
                 htmlarea.js
                 popupwin.js
                 popupdiv.js
                 plugins
                     CSS
                         css.js
                         lang
                             en.js
                     ContextMenu
                         context-menu.js
                         lang
                             de.js
                             en.js
                             nl.js
                             el.js
                         menu.css
                     FullPage
                         img
                             docprop.gif
                         full-page.js
                         popups
                             docprop.html
                         lang
                             en.js
                             ro.js
                         test.html
                     SpellChecker
                         img
                             spell-check.gif
                         spell-check-style.css
                         spell-check-ui.html
                         spell-checker.js
                         lang
                             hu.js
                             de.js
                             en.js
                             cz.js
                             da.js
                             it.js
                             ro.js
                         readme-tech.html
                         spell-check-logic.cgi
                         spell-check-ui.js
                     TableOperations
                         img
                             row-insert-above.gif
                             table-prop.gif
                             cell-insert-after.gif
                             row-split.gif
                             cell-split.gif
                             row-delete.gif
                             row-prop.gif
                             cell-merge.gif
                             row-insert-under.gif
                             cell-delete.gif
                             col-insert-after.gif
                             cell-insert-before.gif
                             cell-prop.gif
                             col-split.gif
                             col-insert-before.gif
                             col-delete.gif
                         lang
                             hu.js
                             de.js
                             fi.js
                             en.js
                             nl.js
                             cz.js
                             da.js
                             no.js
                             el.js
                             it.js
                             ro.js
                         table-operations.js
                 reference.html
             .htaccess
             index.html
         docs
             3.readme_paypal_ipn.html
             whatsnew_1.3.0.2.html
             whatsnew_1.3.8.html
             INSTALL.TXT
             important_site_security_recommendations.html
             osi-certified-120x100.png
             changelog-v1-3-7-1.html
             whatsnew_1.3.7.html
             whatsnew_1.3.0.html
             readme_css_system.html
             changelog-v1-3-5.html
             4.readme_html_email_templates.html
             read_me_onload.html
             5.renaming_the_admin_directory.html
             index.html
             product_types_readme.html
             changelog-v1-3-0.html
             changelog-v1-3-7.html
             whatsnew_1.3.6.html
             0.about_zen_cart.html
             read_me_jscript.html
             2.readme_how_to_upgrade.html
             whatsnew_1.3.0.1.html
             whatsnew_1.3.7-1.html
             changelog-v1-3-6.html
             whatsnew_1.3.5.html
             changelog-v1-3-0-1.html
             changelog-v1-3-0-2.html
             changelog-v1-3-8.html
             1.readme_installation.html
         fantversion.php
         includes
             initsystem.php
             general.js
             form_check.js.php
             functions
                 functions_taxes.php
                 functions_lookups.php
                 audience.php
                 whos_online.php
                 featured.php
                 compatibility.php
                 password_funcs.php
                 functions_customers.php
                 salemaker.php
                 functions_categories.php
                 extra_functions
                     index.html
                 functions_email.php
                 functions_general.php
                 gzip_compression.php
                 banner.php
                 sessions.php
                 html_output.php
                 functions_ezpages.php
                 functions_gvcoupons.php
                 specials.php
                 functions_prices.php
             languages
                 english
                     shippinginfo.php
                     down_for_maintenance.php
                     gv_faq.php
                     products_new.php
                     product_free_shipping_info.php
                     whos_online.php
                     popup_shipping_estimator.php
                     page_2.php
                     password_forgotten.php
                     popup_coupon_help.php
                     checkout_success.php
                     featured_products.php
                     classic
                         header.php
                     unsubscribe.php
                     account_history.php
                     cookie_usage.php
                     credit_cards.php
                     popup_cvv_help.php
                     account_newsletters.php
                     email_extras.php
                     icon_names.php
                     page_not_found.php
                     images
                         icon.gif
                     customers_authorization.php
                     privacy.php
                     create_account_success.php
                     conditions.php
                     checkout_payment.php
                     page_3.php
                     checkout_confirmation.php
                     checkout_process.php
                     document_general_info.php
                     extra_definitions
                         ez_pages_definitions.php
                         classic
                             empty.txt
                         product_free_shipping.php
                         product_music.php
                         document_general.php
                     advanced_search_result.php
                     gv_redeem.php
                     html_includes
                         classic
                             define_page_4.php
                             define_site_map.php
                             define_page_not_found.php
                             define_contact_us.php
                             define_discount_coupon.php
                             define_shippinginfo.php
                             define_page_2.php
                             define_conditions.php
                             define_main_page.php
                             define_checkout_success.php
                             define_privacy.php
                             define_page_3.php
                         define_page_4.php
                         define_site_map.php
                         define_page_not_found.php
                         define_contact_us.php
                         define_discount_coupon.php
                         define_shippinginfo.php
                         define_page_2.php
                         define_conditions.php
                         define_main_page.php
                         define_checkout_success.php
                         define_privacy.php
                         define_page_3.php
                     advanced_search.php
                     reviews.php
                     product_reviews.php
                     button_names.php
                     gv_send.php
                     time_out.php
                     account_password.php
                     ssl_check.php
                     tell_a_friend.php
                     download_time_out.php
                     meta_tags.php
                     checkout_payment_address.php
                     shopping_cart.php
                     header.php
                     index.php
                     products_all.php
                     discount_coupon.php
                     account.php
                     address_book.php
                     create_account.php
                     modules
                         payment
                             freecharger.php
                             authorizenet_echeck.php
                             authorizenet_aim.php
                             classic
                                 empty.txt
                             paypalwpp.php
                             nochex_apc.php
                             authorizenet.php
                             cod.php
                             linkpoint_api.php
                             cc.php
                             paypal.php
                             moneyorder.php
                             paypaldp.php
                         order_total
                             ot_subtotal.php
                             classic
                                 empty.txt
                             ot_group_pricing.php
                             ot_shipping.php
                             ot_gv.php
                             ot_coupon.php
                             ot_cod_fee.php
                             ot_tax.php
                             ot_loworderfee.php
                             ot_total.php
                         shipping
                             usps.php
                             freeshipper.php
                             classic
                                 empty.txt
                             ups.php
                             item.php
                             zones.php
                             perweightunit.php
                             flat.php
                             storepickup.php
                             freeoptions.php
                             table.php
                     login.php
                     other_images_names.php
                     site_map.php
                     popup_search_help.php
                     checkout_shipping_address.php
                     account_history_info.php
                     account_notifications.php
                     product_music_info.php
                     account_edit.php
                     page_4.php
                     product_reviews_info.php
                     contact_us.php
                     product_reviews_write.php
                     jeans
                         header.php
                     info_shopping_cart.php
                     checkout_shipping.php
                     download.php
                     specials.php
                     logoff.php
                     address_book_process.php
                     product_info.php
                     document_product_info.php
                 classic
                     empty.txt
                 english.php
             spiders.txt
             index_filters
                 music_genre_filter.php
                 default_filter.php
                 record_company_filter.php
             application_bottom.php
             autoload_func.php
             application_top.php
             filenames.php
             auto_loaders
                 nochex_apc.core.php
                 config.core.php
                 overrides
                     index.html
                 index.html
                 paypal_ipn.core.php
             .htaccess
             index.html
             extra_cart_actions
                 index.html
             counter.php
             init_includes
                 init_cart_handler.php
                 init_database.php
                 init_templates.php
                 init_special_funcs.php
                 init_paypal_ipn_sessions.php
                 init_customer_auth.php
                 init_sefu.php
                 init_currencies.php
                 init_file_db_names.php
                 init_general_funcs.php
                 init_category_path.php
                 init_sanitize.php
                 overrides
                     index.html
                 index.html
                 init_add_crumbs.php
                 init_tlds.php
                 init_gzip.php
                 init_db_config_read.php
                 init_ipn_postcfg.php
                 init_sessions.php
                 init_nochex_apc_sessions.php
                 init_header.php
                 init_languages.php
             modules
                 product_listing_alpha_sorter.php
                 featured_products.php
                 classic
                     empty.txt
                 new_products.php
                 ezpages_bar_header.php
                 debug_blocks
                     product_info_prices.php
                     shopping_cart_contents.php
                 product_listing.php
                 checkout_address_book.php
                 pages
                     ssl_check
                         header_php.php
                     unsubscribe
                         header_php.php
                     checkout_payment
                         jscript_main.php
                         header_php.php
                     account
                         jscript_main.php
                         header_php.php
                     gv_send
                         header_php.php
                     logoff
                         header_php.php
                     account_password
                         jscript_form_check.php
                         header_php.php
                     product_free_shipping_info
                         main_template_vars_product_type.php
                         jscript_textarea_counter.js
                         jscript_main.php
                         header_php.php
                         main_template_vars.php
                     advanced_search_result
                         header_php.php
                     popup_attributes_qty_prices
                         jscript_main.php
                         header_php.php
                     reviews
                         header_php.php
                     download_time_out
                         header_php.php
                     page
                         header_php.php
                     shopping_cart
                         jscript_main.php
                         header_php.php
                     conditions
                         header_php.php
                     popup_search_help
                         jscript_main.php
                         header_php.php
                     contact_us
                         on_load_main.js
                         header_php.php
                     popup_shipping_estimator
                         jscript_addr_pulldowns.php
                         header_php.php
                     account_newsletters
                         jscript_main.php
                         header_php.php
                     privacy
                         header_php.php
                     product_reviews
                         late_header_php.php
                         jscript_main.php
                         header_php.php
                     address_book
                         jscript_main.php
                         header_php.php
                     account_edit
                         jscript_form_check.php
                         header_php.php
                     featured_products
                         header_php.php
                     popup_cvv_help
                         jscript_main.php
                         header_php.php
                     popup_coupon_help
                         jscript_main.php
                         header_php.php
                     checkout_success
                         header_php.php
                     checkout_confirmation
                         jscript_main.php
                         header_php.php
                     product_reviews_write
                         jscript_main.php
                         header_php.php
                     download
                         header_php.php
                     popup_image_additional
                         jscript_main.php
                         header_php.php
                     tell_a_friend
                         header_php.php
                     create_account_success
                         header_php.php
                     advanced_search
                         jscript_main.php
                         header_php.php
                     specials
                         header_php.php
                         main_template_vars.php
                     product_reviews_info
                         jscript_main.php
                         header_php.php
                     checkout_payment_address
                         on_load_main.js
                         jscript_addr_pulldowns.php
                         jscript_main.php
                         header_php.php
                     info_shopping_cart
                         header_php.php
                     document_product_info
                         main_template_vars_product_type.php
                         jscript_textarea_counter.js
                         jscript_main.php
                         header_php.php
                         main_template_vars.php
                     gv_faq
                         header_php.php
                     customers_authorization
                         header_php.php
                     product_music_info
                         main_template_vars_product_type.php
                         jscript_textarea_counter.js
                         jscript_main.php
                         header_php.php
                         main_template_vars.php
                     checkout_shipping
                         header_php.php
                     products_all
                         header_php.php
                     page_3
                         header_php.php
                     down_for_maintenance
                         header_php.php
                     site_map
                         header_php.php
                     account_history_info
                         jscript_main.php
                         header_php.php
                     page_2
                         header_php.php
                     account_notifications
                         header_php.php
                     discount_coupon
                         header_php.php
                     create_account
                         jscript_form_check.php
                         on_load_main.js
                         jscript_addr_pulldowns.php
                         header_php.php
                     popup_image
                         jscript_main.php
                         header_php.php
                     password_forgotten
                         header_php.php
                     account_history
                         header_php.php
                     checkout_shipping_address
                         on_load_main.js
                         jscript_addr_pulldowns.php
                         jscript_main.php
                         header_php.php
                     shippinginfo
                         header_php.php
                     login
                         jscript_form_check.php
                         on_load_main.js
                         jscript_addr_pulldowns.php
                         jscript_main.php
                         header_php.php
                     product_info
                         main_template_vars_product_type.php
                         jscript_textarea_counter.js
                         jscript_main.php
                         header_php.php
                         main_template_vars.php
                     cookie_usage
                         header_php.php
                     page_4
                         header_php.php
                     index
                         header_php.php
                         main_template_vars.php
                     gv_redeem
                         header_php.php
                     checkout_process
                         header_php.php
                     document_general_info
                         main_template_vars_product_type.php
                         jscript_textarea_counter.js
                         jscript_main.php
                         header_php.php
                         main_template_vars.php
                     products_new
                         header_php.php
                     address_book_process
                         on_load_main.js
                         jscript_addr_pulldowns.php
                         jscript_main.php
                         header_php.php
                     redirect
                         header_php.php
                     page_not_found
                         header_php.php
                     time_out
                         on_load_main.js
                         header_php.php
                 product_prev_next.php
                 category_row.php
                 specials_index.php
                 category_icon_display.php
                 checkout_process.php
                 listing_display_order.php
                 send_or_spend.php
                 ezpages_bar_footer.php
                 column_single.php
                 payment
                     freecharger.php
                     authorizenet_echeck.php
                     authorizenet_aim.php
                     paypalwpp.php
                     nochex_apc
                         logs
                             index.html
                         nochex_apc_admin_notification.php
                         nochex_functions.php
                     nochex_apc.php
                     authorizenet.php
                     cod.php
                     paypal
                         logs
                             index.html
                         paypalwpp_admin_notification.php
                         paypal_functions.php
                         paypal_admin_notification.php
                         tpl_ec_button.php
                         paypal_curl.php
                         ipn_application_top.php
                     linkpoint_api
                         .htaccess
                         index.html
                         linkpoint_api_admin_notification.php
                         class.linkpoint_api.php
                         REPLACE_THIS_FILE_WITH_YOUR_KEY_FILE.pem
                     linkpoint_api.php
                     cc.php
                     paypal.php
                     moneyorder.php
                     authorizenet
                         authorizenet_admin_notification.php
                     paypaldp.php
                 column_right.php
                 categories_tabs.php
                 attributes.php
                 meta_tags.php
                 order_total
                     ot_subtotal.php
                     ot_group_pricing.php
                     ot_shipping.php
                     ot_gv.php
                     ot_coupon.php
                     ot_cod_fee.php
                     ot_tax.php
                     ot_loworderfee.php
                     ot_total.php
                 footer.php
                 create_account.php
                 products_quantity_discounts.php
                 main_product_image.php
                 checkout_new_address.php
                 media_manager.php
                 column_left.php
                 additional_images.php
                 shipping
                     usps.php
                     freeshipper.php
                     ups.php
                     item.php
                     zones.php
                     perweightunit.php
                     flat.php
                     storepickup.php
                     freeoptions.php
                     table.php
                 shipping_estimator.php
                 upcoming_products.php
                 extra_definitions.php
                 also_purchased_products.php
                 extra_functions.php
                 sideboxes
                     music_genres.php
                     banner_box2.php
                     whos_online.php
                     ezpages.php
                     featured.php
                     whats_new.php
                     classic
                         empty.txt
                     currencies.php
                     product_notifications.php
                     order_history.php
                     categories.php
                     record_companies.php
                     best_sellers.php
                     information.php
                     search_header.php
                     reviews.php
                     tell_a_friend.php
                     more_information.php
                     languages.php
                     shopping_cart.php
                     banner_box_all.php
                     document_categories.php
                     manufacturers.php
                     search.php
                     banner_box.php
                     specials.php
                     manufacturer_info.php
                 require_languages.php
                 downloads.php
             templates
                 template_default
                     template_info.php
                     popup_attributes_qty_prices
                         tpl_main_page.php
                     images
                         scr_template_default.jpg
                         stars_3_small.gif
                         stars_3.gif
                         stars_1_small.gif
                         stars_4_small.gif
                         box_products_notifications_remove.gif
                         tile_back.jpg
                         icons
                             cc2.gif
                             cc1.gif
                             cart.gif
                             shipping_ups.gif
                             success.gif
                             cc7.gif
                             icon_status_green_light.gif
                             small_delete.gif
                             cc4.gif
                             cc5.gif
                             icon_status_red_light.gif
                             icon_status_yellow.gif
                             shipping_usps.gif
                             cvv2amex.gif
                             icon_status_green.gif
                             cc3.gif
                             icon_status_red.gif
                             warning.gif
                             cc6.gif
                             cvv2visa.gif
                             error.gif
                         box_products_notifications.gif
                         free.gif
                         stars_2_small.gif
                         stars_2.gif
                         stars_1.gif
                         box_write_review.gif
                         logo.gif
                         stars_5.gif
          &n