Hi.. I don't know what I'm doing wrong.. I'm trying to get the filesize and date of a file.. but an error appears...
The function to get the name of the file
Code: Select all
їphp]<?php
// Open a known directory, and proceed to read its contents
function getFile($dir)
{
//array for the results
$dir_array=Array();
// check if the filename is a directory
if (is_dir($dir))
{
// open the directory
if ($handle = opendir($dir))
{
// read the names of the files in the directory
// loop (end when all the files have been read)
while (($file = readdir($handle)) !== false)
{
// get rid of the filenames that will not need to be displayed
if(($file!=".") && ($file!="..") && ($file!="Drop") && ($file!=".DS_Store") && ($file!="drop box"))
{
$ext = strrchr($file, "."); // check for file extension
if($ext == FALSE) // If doesn't have extension
{
}
else //If have extension
{
$file .= $ext; //add the extension to filename
}
// put the filenames retrieved in the array
$dir_arrayї]=($file);
}
}
return $dir_array; // return the array
closedir($handle);
}
}
}
?>ї/php]Code: Select all
їphp]<?php
include("directory_function.php");
$dirName = "/Users/test/Sites/document/agreements";
print "dirName: $dirName";
$results_array = Array();
$results_array = getFile($dirName);
print "<table border="1">";
print "<th>
<tr>
<td><b>file name:</b></td>
<td><b>file size:</b></td>
<td><b>date:</b></td>
</tr>
</th>";
// For names to folders
foreach ($results_array as $filename)
{
clearstatcache ();
$Dirfile = $dirName; // dirName (main)
$Dirfile .= $filename; // filename
$Dirfile .= "/";
//check if dir
$dir_is = is_dir($Dirfile);
// if it IS a dir
if($dir_is == TRUE)
{
print "<tr>";
// print the filename
print "<td>";
print "file: $filename<br>";
print "</td>";
//print the filesize
print "<td>";
$size = filesize($Dirfile);
print "file size: $size<br>";
print "</td>";
//print the date
print "<td>";
$datemod = date("m/d/y", filemtime($Dirfile));
print "date: $datemod";
print "</td>";
print "</tr>";
}
// if it IS NOT a dir
Else
{
$file = $dirName; // dirName (main)
$file .= "/";
$file .= $filename; // filename
//print "$. file: $file";
print "<tr>";
// print the filename
print "<td>";
//$ext = strchr($file,"."); // get extention
print "file: $filename<br>";
//print "ext: $ext";
print "</td>";
// print the filesize
print "<td>";
$size = filesize($file);
print "file:$file<br>";
print "file size: $size<br>";
print "</td>";
// print the date
print "<td>";
$datemod = date("m/d/y", filemtime($file));
print "date: $datemod";
print "</td>";
print "</tr>";
}
}
print "</table>";
?>ї/php](The first file works fine.. The filesize is displayed.. But after that.. An Error occurs)
Warning: stat failed for /Users/test/Sites/document/agreements/G4 Nomenclature (20 Apr.sit.sit (errno=2 - No such file or directory) in /Users/test/Sites/engg/php_test/directory.php on line 93
The errors i get for date:
(The first file works fine.. The filesize is displayed.. But after that.. An Error occurs)
Warning: stat failed for /Users/test/Sites/document/agreements/G4 Nomenclature (20 Apr.sit.sit (errno=2 - No such file or directory) in /Users/test/Sites/engg/php_test/directory.php on line 100