A time ago to write a PHP class, do not know if there is no use Oh! (Add note)

Source: Internet
Author: User
Tags chmod continue copy file system mkdir net php class
?
/***********************************************************************************/
/*/                                                                               /*/
/*/program:file System Class (FSC)/*/
/*/PHP programer: Wu Di (James Wu)/*/
/*/email:wu-shuang@163.net/*/
/*/homepage:http://www.dev-php.com/*/
/*/date:2002-01-24/*/
/*/                                                                               /*/
/***********************************************************************************/

Class fsc{

/**************************************************************************/
Function Name: Getfilesource
Function: Get the contents of the specified file
Parameters: $file target file
/**************************************************************************/
function Getfilesource ($file) {
if ($fp =fopen ($file, ' R ')) {
$filesource =fread ($fp, FileSize ($file));
Fclose ($FP);
return $filesource;
}
Else
return false;
}
/**************************************************************************/
Function Name: WriteFile
Function: Create a new file and write to the content, if the specified filename already exists, it will directly overwrite
Parameters: $file--New file name
$source File Contents
/**************************************************************************/
function WriteFile ($file, $source) {
if ($fp =fopen ($file, ' W ')) {
$filesource =fwrite ($fp, $source);
Fclose ($FP);
return $filesource;
}
Else
return false;
}
/**************************************************************************/
Function Name: MoveFile
Features: Moving files
Parameters: $file--file name to be moved
$destfile--Target file name
$overwrite Overwrite if the destination file exists. Default is overwrite.
$bak whether to keep the original file by default is to delete the original file

/**************************************************************************/
function MoveFile ($file, $destfile, $overwrite =1, $bak =0) {
if (file_exists ($destfile)) {
if ($overwrite)
Unlink ($destfile);
Else
return false;
}
if ($CF =copy ($file, $destfile)) {
if (! $bak)
Return (unlink ($file));
}
return ($CF);
}
/**************************************************************************/
Function Name: Movedir
Function: This is the support function of the next number move, the function is mobile directory
/**************************************************************************/
function Movedir ($dir, $destdir, $overwrite =1, $bak =0) {
@set_time_limit (600);
if (!file_exists ($destdir))
Fsc::notfate_any_mkdir ($destdir);
if (file_exists ($dir) && (Is_dir ($dir))
{
if (substr ($dir, -1)!= '/') $dir. = '/';
if (file_exists ($destdir) && (Is_dir ($destdir)) {
if (substr ($destdir, -1)!= '/') $destdir. = '/';
$h =opendir ($dir);
while ($file =readdir ($h)) {
if ($file = = '. ' | | $file = = '.. ')
{
Continue
$file = "";
}
if (Is_dir ($dir. $file)) {
if (!file_exists ($destdir. $file))
Fsc::notfate_mkdir ($destdir. $file);
Else
chmod ($destdir. $file, 0777);
Fsc::movedir ($dir. $file, $destdir. $file, $overwrite, $bak);
FSC::d elforder ($dir. $file);
}
Else
{
if (File_exists ($destdir. $file)) {
if ($overwrite) unlink ($destdir. $file);
else{
Continue
$file = "";
}
}
If copy ($dir. $file, $destdir. $file))
if (! $bak)
if (File_exists ($dir. $file) &&is_file ($dir. $file))
@unlink ($dir. $file);
}
}
}
Else
return false;
}
Else
return false;
}
/**************************************************************************/
Name of function: Move
Features: Moving files or directories
Parameters: $file--Source files/directories
$path--Target path
$overwrite-whether to overwrite the move if the file already exists in the destination path
--The default value is 1, that is, overwrite
$bak--Keep backup (original file/directory)
/**************************************************************************/
function Move ($file, $path, $overwrite =1, $bak =0)
{
if (file_exists ($file)) {
if (Is_dir ($file)) {
if (substr ($file, -1) = = '/') $dirname =basename (substr ($file, 0,strlen ($file)-1));
else $dirname =basename ($file);
if (substr ($path, -1)!= '/') $path. = '/';
if ($file!= '. ') $file!= ' ... ' | | $file!= '. /'|| $file!= './') $path. = $dirname;
Fsc::movedir ($file, $path, $overwrite, $bak);
if (! $bak) FSC::d elforder ($file);
}
else{
if (file_exists ($path)) {
if (Is_dir ($path)) chmod ($path, 0777);
else {
if ($overwrite)
@unlink ($path);
Else
return false;
}
}
Else
Fsc::notfate_any_mkdir ($path);
if (substr ($path, -1)!= '/') $path. = '/';
Fsc::movefile ($file, $path. basename ($file), $overwrite, $bak);
}
}
Else
return false;
}
/**************************************************************************/
Function Name: Delforder
Function: Delete the directory, regardless of whether there are files or subdirectories, delete all Oh, be careful not to delete the wrong Oh!
Parameters: $file--Source files/directories

/**************************************************************************/
function Delforder ($file) {
chmod ($file, 0777);
if (Is_dir ($file)) {
$handle = Opendir ($file);
while ($filename = Readdir ($handle)) {
if ($filename!= "." && $filename!= "...")
{
FSC::d elforder ($file.) /". $filename);
}
}
Closedir ($handle);
Return (RmDir ($file));
}
else {
Unlink ($file);
}
}
/**************************************************************************/
Function Name: Notfate_mkdir
Function: Create a new directory, this is a piece of code from Php.net. Make up for the mkdir.
Parameters: $dir--Directory name

/**************************************************************************/
function Notfate_mkdir ($dir, $mode =0777) {
$u =umask (0);
$r =mkdir ($dir, $mode);
Umask ($u);
return $r;
}
/**************************************************************************/
Function Name: Notfate_any_mkdir
Function: Create a new directory that is a bit different from the notfate_mkdir above, because it has an additional any to create a multilevel catalog
such as: Notfate_any_mkdir ("ABC/ABC/ABC/ABC/ABC")
Parameters: $dirs--Directory name

/**************************************************************************/
function Notfate_any_mkdir ($dirs, $mode =0777)
{
if (!strrpos ($dirs, '/'))
{
Return (Fsc::notfate_mkdir ($dirs, $mode));
}else
{
$forder =explode ('/', $dirs);
$f = ';
for ($n =0; $n <count ($forder); $n + +)
{
if ($forder [$n]== ') continue;
$f. = (($n ==0) && ($forder [$n]<> ')] ("):(" /'). $forder [$n];
if (file_exists ($f)) {
chmod ($f, 0777);
Continue
}
Else
{
if (Fsc::notfate_mkdir ($f, $mode)) continue;
Else
return false;
}
}
return true;
}
}

/*********************************************************************************/
/*/End Class FSC/*/
/*********************************************************************************/
}
?>

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.