Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Next »

The cFileHandler class encapsules functionalities for dealing with files.

 

 

Methods:

All provided functionalities are in a public static context.

methodNameDescriptionExample
 chmod($filename, $mode)

This method can be used to change file permissions on a *nix system.

Expected parameters:

  • $filename: the full path name of a file (including the filename)
  • $mode: permission you want to set in octal mode
chmod('/var/www/index.php,777);

The call of the method above grants read, write and execute rights.

copy($filename, $destination)

This method copies a file to a given location. Existing files will be overwritten

Expected parameters:

  • $filename: the full path name of a file (including the filename)
  • $destination: the full path name of a file (including the filename)

Returns: bool

chmod('/var/www/index.php', '/var/www/index2.php');

The call of the method above copies the index.php file to the index2.php file.

   
exists($filename)

This method checks if a file exists at the given location

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Returns: bool

exists('/var/www/index.php');

The call of the method above returns true if the 'var/www/index.php' file exists, otherwise false.

getExtension($basename)

This method returns the file extension of the given file

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Returns: string

getExtension('/var/www/index.php');

The call of the method above returns the string 'php'.

info($filename)

This method returns information about the given file. The returing array includes the following information:

  • size (byte)
  • atime (unix timestamp: last access)
  • ctime (unix timestamp: creation)
  • mtime (unix timestamp: last modified)
  • perms (4 octal digit: file permissions)
  • extension (string: mime type of the file)

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Returns: array

 
isDirectoryEmpty($dir)

This method returns checks if the given directory is empty.

Expected parameters:

  • $dir: the full path name of a directory

Returns: bool

In my opinion this method should be transfered to the cDirHandler class.

isDirectoryEmpty('/var/www/test');

The call of the method above returns true if the given directory exists, otherwise false.

move($filename, $destination)

This method changes the location of the given file

Expected parameters:

  • $filename: the full path name of a file (including the filename)
  • $destination: the full path name of a file (including the filename)

Returns: bool

move('/var/www/index.php', '/var/www/test/index.php');

The call of the method above moves the index.php file from path '/var/www/' to '/var/www/test/'.

 

read($filename, $length = 0, $offset = 0, $reverse = false)

This method reads bytes from the given file.

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Optional parameters:

  • $length (int: number of bytes to read)
  • $offset (int: byte offset)
  • $reverse (bool: start reading from the front or from the end of the file)

Returns: bool

 


 

readable($filename)

This method checks if the given file is readable.

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Returns: bool

 


 

readLine($filename, $lines = 0, $lineoffset = 0)

This method reads a line from the given file.

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Optional parameters:

  • $lines(int: number of lines to read)
  • $lineoffset (int: lines offset)

Returns:

  • string: read only one line
  • array of strings: read more than one line
  • bool: read nothing
     
 

recursiveCopy($filename, $destination)

This method should be transfered to the cDirHandler class and refactored, highly recommended!

Siehe cDirHandler
 recursiveRmdir($dirname)

This method should be transfered to the cDirHandler class, highly recommended!

Siehe cDirHandler

remove($filename)

This method removes the given file from the filesystem.

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Returns: bool

 


 

rename($filename, $new_filename)

This method renames the given file from the filesystem.

Expected parameters:

  • $filename: the full path name of a file (including the filename)
  • $new_filename: the full path name of a file (including the filename)

Returns: bool

 
setDefaultDirPerms($pathname)

This method should be transfered to the cDirHandler class, highly recommended!

Siehe cDirHandler
setDefaultFilePerms($filename)

This method sets default permissions to the given file

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Returns: bool

 
truncate($filename)

This method clears the content of the given file

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Returns: bool

 


 

validateFilename($filename, $notifyAndExitOnFailure = true)

This method validates the filename of the given file with CONENTIDO standard.

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Optional parameters:

  • $notifyAndExitOnFailure(bool: show notification and exit the script)

Returns: bool

 
write($filename, $content, $append = false)

This method writes data to the given file

Expected parameters:

  • $filename: the full path name of a file (including the filename)
  • $content: content you want to write

Optional parameters:

  • $append(bool: flag to append the content to a existing file

Returns: bool

 
 writeable($filename)

This method checks if the given file is writeable

Expected parameters:

  • $filename: the full path name of a file (including the filename)

Returns: bool

 
writeLine($filename, $content, $append = false)

This method writes a line to the given file

Expected parameters:

  • $filename: the full path name of a file (including the filename)
  • $content: content you want to write

Optional parameters:

  • $append(bool: flag to append the content to a existing file

Returns: bool

 
  • No labels