XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
Public Member Functions | Static Public Member Functions | List of all members
FileHandler Class Reference

Public Member Functions

 getRealPath ($source)
 
 copyDir ($source_dir, $target_dir, $filter=null, $type=null)
 
 copyFile ($source, $target, $force= 'Y')
 
 readFile ($filename)
 
 writeFile ($filename, $buff, $mode="w")
 
 removeFile ($filename)
 
 rename ($source, $target)
 
 moveFile ($source, $target)
 
 moveDir ($source_dir, $target_dir)
 
 readDir ($path, $filter= '', $to_lower=FALSE, $concat_prefix=FALSE)
 
 makeDir ($path_string)
 
 removeDir ($path)
 
 removeBlankDir ($path)
 
 removeFilesInDir ($path)
 
 filesize ($size)
 
 getRemoteResource ($url, $body=null, $timeout=3, $method= 'GET', $content_type=null, $headers=array(), $cookies=array(), $post_data=array(), $request_config=array())
 
 getRemoteFile ($url, $target_filename, $body=null, $timeout=3, $method= 'GET', $content_type=null, $headers=array(), $cookies=array(), $post_data=array(), $request_config=array())
 
 returnBytes ($val)
 
 checkMemoryLoadImage (&$imageInfo)
 
 createImageFile ($source_file, $target_file, $resize_width=0, $resize_height=0, $target_type= '', $thumbnail_type= 'crop', $thumbnail_transparent=FALSE)
 
 readIniFile ($filename)
 
 writeIniFile ($filename, $arr)
 
 _makeIniBuff ($arr)
 
 openFile ($filename, $mode)
 
 hasContent ($filename)
 
 exists ($filename)
 
 isDir ($path)
 
 isWritableDir ($path)
 

Static Public Member Functions

static clearStatCache ($target, $include=false)
 
static invalidateOpcache ($target, $force=true)
 

Detailed Description

Contains methods for accessing file system

Author
NAVER (devel.nosp@m.oper.nosp@m.s@xpr.nosp@m.esse.nosp@m.ngine.nosp@m..com)

Definition at line 9 of file FileHandler.class.php.

Member Function Documentation

FileHandler::_makeIniBuff (   $arr)

Make array to ini string

Parameters
array$arrArray
Returns
string

Definition at line 1032 of file FileHandler.class.php.

FileHandler::checkMemoryLoadImage ( $imageInfo)

Check available memory to load image file

Parameters
array$imageInfoImage info retrieved by getimagesize function
Returns
bool TRUE: it's ok, FALSE: otherwise

Definition at line 727 of file FileHandler.class.php.

static FileHandler::clearStatCache (   $target,
  $include = false 
)
static

Clears file status cache

Parameters
string | array$targetfilename or directory
boolean$includeinclude files in the directory

Definition at line 1146 of file FileHandler.class.php.

FileHandler::copyDir (   $source_dir,
  $target_dir,
  $filter = null,
  $type = null 
)

Copy a directory to target

If target directory does not exist, this function creates it

Parameters
string$source_dirPath of source directory
string$target_dirPath of target dir
string$filterRegex to filter files. If file matches this regex, the file is not copied.
string$typeIf set as 'force'. Even if the file exists in target, the file is copied.
Returns
void

Definition at line 39 of file FileHandler.class.php.

FileHandler::copyFile (   $source,
  $target,
  $force = 'Y' 
)

Copy a file to target

Parameters
string$sourcePath of source file
string$targetPath of target file
string$forceY: overwrite
Returns
void

Definition at line 104 of file FileHandler.class.php.

FileHandler::createImageFile (   $source_file,
  $target_file,
  $resize_width = 0,
  $resize_height = 0,
  $target_type = '',
  $thumbnail_type = 'crop',
  $thumbnail_transparent = FALSE 
)

Moves an image file (resizing is possible)

Parameters
string$source_filePath of the source file
string$target_filePath of the target file
int$resize_widthWidth to resize
int$resize_heightHeight to resize
string$target_typeIf $target_type is set (gif, jpg, png, bmp), result image will be saved as target type
string$thumbnail_typeThumbnail type(crop, ratio)
bool$thumbnail_transparentIf $target_type is png, set background set transparent color
Returns
bool TRUE: success, FALSE: failed

Definition at line 765 of file FileHandler.class.php.

FileHandler::exists (   $filename)

Check file exists.

Parameters
string$filenameTarget file name
Returns
bool Returns FALSE if the file does not exists, or Returns full path file(string).

Definition at line 1095 of file FileHandler.class.php.

FileHandler::filesize (   $size)

Makes file size byte into KB, MB according to the size

See Also
self::returnBytes()
Parameters
int$sizeNumber of the size
Returns
string File size string

Definition at line 480 of file FileHandler.class.php.

FileHandler::getRealPath (   $source)

Changes path of target file, directory into absolute path

Parameters
string$sourcepath to change into absolute path
Returns
string Absolute path

Definition at line 18 of file FileHandler.class.php.

FileHandler::getRemoteFile (   $url,
  $target_filename,
  $body = null,
  $timeout = 3,
  $method = 'GET',
  $content_type = null,
  $headers = array(),
  $cookies = array(),
  $post_data = array(),
  $request_config = array() 
)

Retrieves remote file, then stores it into target path.

Parameters
string$urlThe address of the target file
string$target_filenameThe location to store
string$bodyHTTP request body
string$timeoutConnection timeout
string$methodGET/POST
string$content_typeContent type header of HTTP request
string[]$headers Headers key value array.
Returns
bool TRUE: success, FALSE: failed

Definition at line 676 of file FileHandler.class.php.

FileHandler::getRemoteResource (   $url,
  $body = null,
  $timeout = 3,
  $method = 'GET',
  $content_type = null,
  $headers = array(),
  $cookies = array(),
  $post_data = array(),
  $request_config = array() 
)

Return remote file's content via HTTP

If the target is moved (when return code is 300~399), this function follows the location specified response header.

Parameters
string$urlThe address of the target file
string$bodyHTTP request body
int$timeoutConnection timeout
string$methodGET/POST
string$content_typeContent type header of HTTP request
string[]$headers Headers key value array.
string[]$cookies Cookies key value array.
string$post_dataRequest arguments array for POST method
Returns
string If success, the content of the target file. Otherwise: none

Definition at line 520 of file FileHandler.class.php.

FileHandler::hasContent (   $filename)

Check whether the given file has the content.

Parameters
string$filenameTarget file name
Returns
bool Returns TRUE if the file exists and contains something.

Definition at line 1084 of file FileHandler.class.php.

static FileHandler::invalidateOpcache (   $target,
  $force = true 
)
static

Invalidates a cached script of OPcache

Parameters
string | array$targetfilename or directory
boolean$forceforce

Definition at line 1170 of file FileHandler.class.php.

FileHandler::isDir (   $path)

Check it is dir

Parameters
string$dirTarget dir path
Returns
bool Returns FALSE if the dir is not dir, or Returns full path of dir(string).

Definition at line 1107 of file FileHandler.class.php.

FileHandler::isWritableDir (   $path)

Check is writable dir

Parameters
string$pathTarget dir path
Returns
bool

Definition at line 1119 of file FileHandler.class.php.

FileHandler::makeDir (   $path_string)

Creates a directory

This function creates directories recursively, which means that if ancestors of the target directory does not exist, they will be created too.

Parameters
string$path_stringPath of target directory
Returns
bool TRUE if success. It might return nothing when ftp is used and connection to the ftp address failed.

Definition at line 282 of file FileHandler.class.php.

FileHandler::moveDir (   $source_dir,
  $target_dir 
)

Move a directory

This function just wraps rename function.

Parameters
string$source_dirPath of source directory
string$target_dirPath of target directory
Returns
void

Definition at line 214 of file FileHandler.class.php.

FileHandler::moveFile (   $source,
  $target 
)

Move a file

Parameters
string$sourcePath of source file
string$targetPath of target file
Returns
bool Returns TRUE on success or FALSE on failure.

Definition at line 195 of file FileHandler.class.php.

FileHandler::openFile (   $filename,
  $mode 
)

Returns a file object

If the directory of the file does not exist, create it.

Parameters
string$filenameTarget file name
string$modeFile mode for fopen
Returns
FileObject File object

Definition at line 1069 of file FileHandler.class.php.

FileHandler::readDir (   $path,
  $filter = '',
  $to_lower = FALSE,
  $concat_prefix = FALSE 
)

Return list of the files in the path

The array does not contain files, such as '.', '..', and files starting with '.'

Parameters
string$pathPath of target directory
string$filterIf specified, return only files matching with the filter
bool$to_lowerIf TRUE, file names will be changed into lower case.
bool$concat_prefixIf TRUE, return file name as absolute path
Returns
string[] Array of the filenames in the path

Definition at line 230 of file FileHandler.class.php.

FileHandler::readFile (   $filename)

Returns the content of the file

Parameters
string$filenamePath of target file
Returns
string The content of the file. If target file does not exist, this function returns nothing.

Definition at line 127 of file FileHandler.class.php.

FileHandler::readIniFile (   $filename)

Reads ini file, and puts result into array

See Also
self::writeIniFile()
Parameters
string$filenamePath of the ini file
Returns
array ini array (if the target file does not exist, it returns FALSE)

Definition at line 985 of file FileHandler.class.php.

FileHandler::removeBlankDir (   $path)

Remove a directory only if it is empty

Parameters
string$pathPath of the target directory
Returns
void

Definition at line 404 of file FileHandler.class.php.

FileHandler::removeDir (   $path)

Remove all files under the path

Parameters
string$pathPath of the target directory
Returns
void

Definition at line 363 of file FileHandler.class.php.

FileHandler::removeFile (   $filename)

Remove a file

Parameters
string$filenamepath of target file
Returns
bool Returns TRUE on success or FALSE on failure.

Definition at line 169 of file FileHandler.class.php.

FileHandler::removeFilesInDir (   $path)

Remove files in the target directory

This function keeps the directory structure.

Parameters
string$pathPath of the target directory
Returns
void

Definition at line 438 of file FileHandler.class.php.

FileHandler::rename (   $source,
  $target 
)

Rename a file

In order to move a file, use this function.

Parameters
string$sourcePath of source file
string$targetPath of target file
Returns
bool Returns TRUE on success or FALSE on failure.

Definition at line 183 of file FileHandler.class.php.

FileHandler::returnBytes (   $val)

Convert size in string into numeric value

See Also
self::filesize()
Parameters
$valSize in string (ex., 10, 10K, 10M, 10G )
Returns
int converted size

Definition at line 706 of file FileHandler.class.php.

FileHandler::writeFile (   $filename,
  $buff,
  $mode = "w" 
)

Write $buff into the specified file

Parameters
string$filenamePath of target file
string$buffContent to be written
string$modea(append) / w(write)
Returns
void

Definition at line 145 of file FileHandler.class.php.

FileHandler::writeIniFile (   $filename,
  $arr 
)

Write array into ini file

$ini['key1'] = 'value1';<br/>
$ini['key2'] = 'value2';<br/>
$ini['section']['key1_in_section'] = 'value1_in_section';<br/>
$ini['section']['key2_in_section'] = 'value2_in_section';<br/>
self::writeIniFile('exmple.ini', $ini);
See Also
self::readIniFile()
Parameters
string$filenameTarget ini file name
array$arrArray
Returns
bool if array contains nothing it returns FALSE, otherwise TRUE

Definition at line 1016 of file FileHandler.class.php.


The documentation for this class was generated from the following file: