PHP Object-oriented file manipulation class

Source: Internet
Author: User
Object <?php

/*
FileName: classfile.php
Features: object-oriented, File operation class (view files, delete files, upload files)
Author: source of infection
Time: 2007-1-11
*/

Class Classfile
{
Private $dir _name;
Private $file _name;
Private $DH;
Private $file _path;


constructor, open working file directory
function __construct ($PDirName)
{
$this->dir_name = $PDirName;
if (Is_dir ($this->dir_name))

Open Directory
if ($this->dh = Opendir ($this->dir_name) or dir (' path is wrong, please check the path again! '));
}//function __construct ();


Close File directory
function __destruct ()
{
Close Directory
Closedir ($this-&GT;DH);
}//function __destruct ();


Add files to the current folder and check for files with duplicate names
function AddFile ($temp _file)
{
Reading directories
while ($this->file_name = Readdir ($this->dh))
{
if ($this->file_name== $temp _file)//Check for duplicate files that already exist
{
echo ' File duplicate name, change filename ... ';
Exit
}
Else
{
Copy temporary files to the current directory
$up _id = copy ($temp _file, "$this->dir_name/$temp _file");
if (! $up _id)
{
echo ' File upload failed, please send again ... '
Exit
}
Else
{
Unlink ($temp _file); Delete temporary files

echo "<script language= ' JavaScript ' >";
echo alert (\ "File upload succeeded!\"); ";
echo "</script>";
}//if
}//if
}//while
}//function AddFile ();


deleting files
function Delfile ($del _file)
{
if (Is_file ($del _file))
{
$path = "$this->dir_name\/$del _file";
if (unlink ($del _file))
{
echo "<script language= ' JavaScript ' >";
echo alert (\) successfully deleted the file! \');";
echo "</script>";
}

}//if
}//function Delfile ();


Reading files
function Read_file ()
{
$result _file = Array ();
$i = 0;
while ($this->file_name = Readdir ($this->dh))
{
if ($this->file_name== '. ') $this->file_name== ' ... ')
{}
Else
{
$result _file[$i + +] = "$this->dir_name/$this->file_name";
}//if

}//while
return $result _file; Returns an array of file names
}//function Read_file ()
}//class Classfile
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.