List of URL Title and Date of last edit of files present inside a directory

This script uses directory listing , reading content , filemtime() , reading title functions to display Path (URL), title and Date of last modification of all the files of a directory.

Here we have checked the files with extension of .php , same way any other type of files can be checked. If you are reading images present in a directory then you can change the file extension to .jpg of .gif. You can also remove the if – else condition to list all the files irrespective of its file extension.

While using the script you need to edit the path giving relative path details from the present location of the script to directory where files are to be checked.

Here is the sample script.
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Displaying file name Title and date of last modification of all files of a directory</title>
</head>

<body>

<?Php
///////////////function my_strip///////////
function my_strip($start,$end,$total){
$total = stristr($total,$start);
$f2 = stristr($total,$end);
return substr($total,strlen($start),-strlen($f2));
}
/////////////////////End of function my_strip ///
///////////// Reading of file content////
$i=0; // Number of file counter
echo "<table><tr><th>URL ( Path + file name)</th><th>Title</th><th>Date</th></tr>";

$path="dir_name/path/";// Change this  to your directory or path

$handle=opendir($path);
while (($file_name = readdir($handle))!==false) {
$str="";
if(stristr($file_name,".php")){ // We are checking for a perticular file extension, change this to match yours
$url="$path".$file_name;
$contents="";
$fd = fopen ($url, "r"); // opening the file in read mode
while($buffer = fread ($fd,1024)){
$contents .=$buffer;
}
/////// End of reading file content ////////

//////// We will start with collecting title part ///////
$title = my_strip("<title>","</title>",$contents);
$dt=date("Y-m-d",filemtime($url)); // Last modification date of the file

echo "<tr><td>$url</td><td>$title</td><td>$dt</td></tr>";
$i=$i+1;
}// end of if checking file extension
}// end of while reading directory
closedir($handle);
echo "</table>";

echo "Total Number of files checked = $i ";
?>
</body>
</html>
Here we have listed all details of a file but we can also store all these data in a table.
We will learn how to store the list in a MySQL table

File Checking if file exists before deleting
PHP
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com











    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer