Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

How to list all files in a directory and read each of them in PHP

Posted on March 8, 2020 by Habibie

This code snippet is useful to me when I need to read all files inside a directory and showing it on web browser in PHP:

<?php
header('Content-type: text/plain; charset=utf-8');
$dir = "1"; //this is a folder containing files we want to read.
$files = scandir("$dir");
foreach($files as $key=>$value){
	if(!in_array($value, array(".", ".."))){
		echo "Found this file: " . $value . "<br>Begin reading...";
		$currentfile = fopen($dir . "/" . $value, "r") or die("Unable to read the file!");
		echo fread($currentfile, filesize($dir . "/" . $value));
		echo "Reading finished.";
	}
}
Post Views: 358
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme