Create a function in a multilevel directory function that invokes the specified file under create specified:
Public function create_dir ($dir,$mode=0777) { returnis_dir ($dir) or ($this->create_dir (dirname($dirmkdir( $dir $mode )); }
Creates the specified file under the specified path, a string $path (which requires a file name and suffix), a Boolean $over _write whether to overwrite the file, and an int $time set the time. The default is the current system time, and int $atime set access time. The default is the current system time. The function called Create_dir to create a directory function and delete the Unlink_file function as follows:
Public functionCreate_file ($path,$over _write=FALSE,$time=NULL,$atime=NULL) { $path=$this->dir_replace ($path); $time=Empty($time) ? Time() :$time; $atime=Empty($atime) ? Time() :$atime; if(file_exists($path) &&$over _write) { $this->unlink_file ($path); } $aimDir=dirname($path); $this->create_dir ($aimDir); return Touch($path,$time,$atime); }
Delete non-empty directory functions, Description: Can only delete non-system and specific permissions of the file, otherwise an error occurs, String$dirname directory path, boolean$is_all whether to delete all, Boolean $del _dir whether to delete the directory, the function is as follows:
Public functionRemove_dir ($dir _path,$is _all=FALSE) { $dirName=$this->dir_replace ($dir _path); $handle= @Opendir($dirName); while(($file= @Readdir($handle)) !==FALSE) { if($file! = '. ' &&$file! = ' ... ') { $dir=$dirName. ‘/‘ .$file; if($is _all) { Is_dir($dir) ?$this->remove_dir ($dir) :$this->unlink_file ($dir); } Else { if(Is_file($dir)) { $this->unlink_file ($dir); } } } } Closedir($handle); return@rmdir($dirName); }
Replace the character function corresponding to//in the path:
Public function dir_replace ($path) { returnstr_replace('//', '/', Str_replace (' \ \ ', '/',$path)); }
/** * Specify file Encoding conversion * @param string $path file path * @param string $input _code Original encoding * @param string $out _code output Code * @return Boolean*/ Public functionChange_file_code ($path,$input _code,$out _code) { if(Is_file($path))//checks if the file exists, executes the transcoding if it exists, returns true { $content=file_get_contents($path); $content=string:: Chang_code ($content,$input _code,$out _code); $fp=fopen($path, ' W '); return fputs($fp,$content) ?TRUE:FALSE; fclose($fp); } }
/**
* Get upload file information
* @param $file File property information
* @return Array
*/
Public functionGet_upload_file_info ($file) { $file _info=$_files[$file];//get basic information about uploading files $info=Array(); $info[' type '] =Strtolower(Trim(stripslashes(Preg_replace("/^(.+?);. *$/"," \\1 ",$file _info[' type ']));//Get file Type $info[' temp '] =$file _info[' Tmp_name '];//get upload file temporarily save directory on server $info[' size '] =$file _info[' Size '];//get upload file size $info[' ERROR '] =$file _info[' Error '];//get File Upload errors $info[' name '] =$file _info[' Name '];//Get upload file name $info[' ext '] =$this->get_ext ($file _info[' name ']);//get the upload file suffix return $info; }
/**
* Get file path information
* @param $full _path full path
* @return Arrayobject
*/
Public function Get_file_type ($path) { //pathinfo () functions return the information of the file path as an array. //---------$file _info = PathInfo ($path); Echo file_info[' extension ';----------// //extension get file suffix name " PathInfo ($path, pathinfo_extension) "-----DIRNAME Get File path" PathInfo ($path, Pathinfo_dirname) "-----basename get file Full filename" PathInfo ($path, pathinfo_basename) "-----filename" pathinfo ($path, Pathinfo_filename) " return pathinfo($path); }
/**
* Returns information for specified files and directories
* @param string $file
* @return Arrayobject
*/
Public functionList_info ($file) { $dir=Array(); $dir[' filename '] =basename($file);//returns the file name portion of the path. $dir[' pathname '] =Realpath($file);//returns the absolute path name. $dir[' owner '] =Fileowner($file);//the user ID (owner) of the file. $dir[' perms '] =fileperms($file);//returns the inode number of the file. $dir[' inode '] =Fileinode($file);//returns the inode number of the file. $dir[' Group '] =Filegroup($file);//returns the group ID of the file. $dir[' path '] =dirname($file);//returns the directory name portion of the path. $dir[' atime '] =Fileatime($file);//returns the last access time for a file. $dir[' ctime '] =Filectime($file);//returns the time when the file was last changed. $dir[' perms '] =fileperms($file);//the permission to return a file. $dir[' size '] =filesize($file);//returns the file size. $dir[' type '] =filetype($file);//returns the file type. $dir[' ext '] =Is_file($file) ?PathInfo($file, pathinfo_extension): ";//returns the file suffix name $dir[' mtime '] =Filemtime($file);//returns the last modified time of the file. $dir[' isdir '] =Is_dir($file);//determines whether the specified file name is a directory. $dir[' isfile '] =Is_file($file);//determines whether the specified file is a regular file. $dir[' islink '] =Is_link($file);//determines whether the specified file is a connection. $dir[' isreadable '] =is_readable($file);//determines whether the file is readable. $dir[' iswritable '] =is_writable($file);//determine if the file is writable. $dir[' isupload '] =Is_uploaded_file($file);//determine if the file was uploaded via HTTP POST. return $dir; }
Full package code content is limited, please go below to download: Http://pan.baidu.com/s/1gf4AGoF
Password: Iqun
PHP Create multi-level directory complete Encapsulation class operation