<?php
/*
PHP version:28 April 2005
Author:move2rent
Purpose: Read a file in a directory
*/
The directory to read
$folder = "H:/temp";
Open Directory
$FP =opendir ($folder);
Reading Table of Contents
while (false!= $file =readdir ($fp))
{
List all files and remove '. ' and '.. '
if ($file!= '. ' && $file!= ' ... ')
{
$file = "$folder/$file";
$file = "$file";
assigning to arrays
$arr _file[]= $file;
}
}
Output results
if (Is_array ($arr _file))
{
while (list ($key, $value) =each ($arr _file))
{
echo "$key => $value <br>";
}
}
Close Directory
Closedir ($FP);
?>
----------------------
Read file 2 in a directory
<?php
/*php version:30 April 2005
Author:move2rent
Purpose: Read the file in a directory two */
/*----------------------------------*/
function Listfiles ($dir)
{
Open Directory
$handle =opendir ($dir);
Reading Table of Contents
while (false!= ($file =readdir ($handle))
{
List all files and remove '. ' and '.. '
if ($file!= '. ') && $file!= ' ... ')
{
Whether the resulting file name is a directory
if (Is_dir ("$dir/$file"))
{
Listing files in a directory
Listfiles ("$dir/$file");
}
Else
{
Open the file if it is a file
$FP =fopen ("$dir/$file", "R");
Read the contents of the file
$data =fread ($fp, FileSize ("$dir/$file"));
if ($data)
Assign the read to an array
$file _array[]= "$dir/$file";
/*foreach ($file _array as $key => $value)
{
echo "$value <br>";
}
*/
echo Count ($file _array);
Output results
while (list ($key, $value) =each ($file _array))
{
echo "$key => $value <br>";
}
}
}
}
}
/*------------------------------------------*/
Call
$dir = "H:/temp";
Listfiles ($dir);
?>
-----------------------------------------------
Create the directory if it does not exist
<?php
/*
PHP version:28 April 2005
Author:move2rent
Purpose: Reads a file in a directory and creates it if it does not exist
*/
$folder = "H:/TEMP1";
Open Directory
@ $fp =opendir ($folder);
Create the directory if it does not exist
if (! $fp)
{
Create a table of contents
mkdir ($folder);
Modify permissions for this directory
chmod ($folder, ' 0755 ');
echo "The folder create Success!";
}
Else
{
echo "The folder have exists."
}
?>