{"id":233,"date":"2020-04-16T23:28:00","date_gmt":"2020-04-16T23:28:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=233"},"modified":"2020-12-06T23:30:05","modified_gmt":"2020-12-06T23:30:05","slug":"php-display-directory-contents","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/php-display-directory-contents\/","title":{"rendered":"PHP: Display directory contents"},"content":{"rendered":"\n<p>For security reasons, most servers on the Internet do not show the contents of a directory if the directory address is typed. The user is either redirected to index.whatever, a default page, page not found or access denied. Thus the list of files in the directory are not displayed.<\/p>\n\n\n\n<p>If you need to show the contents of your directory, you can use the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>exec(\"ls\", $output, $return);\nforeach ($output as $file ) {\n   if ($file != \"index.php\") { \n      print \"&lt;a href='$file'>$file&lt;\/a>&lt;br>\"; \n   }\n}<\/code><\/pre>\n\n\n\n<p>If exec() is blocked by your server due to SELinux settings, you can use proc_open() instead.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For security reasons, most servers on the Internet do not show the contents of a directory if the directory address is typed. The user is either redirected to index.whatever, a default page, page not found or access denied. Thus the list of files in the directory are not displayed. If you need to show the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[94,35],"class_list":["post-233","post","type-post","status-publish","format-standard","hentry","category-linux","tag-bash","tag-linux"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=233"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/233\/revisions"}],"predecessor-version":[{"id":234,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/233\/revisions\/234"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}