Child pages
  • cFileHandler
Skip to end of metadata
Go to start of metadata

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

copy('/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.

fileNameIsDot($fileName)

This method checks if the given filename is  '.' or '..'.

Expected parameters:

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

Returns: bool


fileNameIsDot('.');

The call of the method above returns true.

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 was moved to cDirHandler class with version 4.9.3 and is deprecated now.see cDirHandler
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

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

The call of the method above returns the content of the index.php file.

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

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

The call of the method above moves returns true if the index.php file is readable, otherwise false.

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
     
readableLine('/var/www/index.php');

The call of the method above returns the first line of the content from the index.php file.

recursiveCopy($filename, $destination)

This method was moved to cDirHandler class with version 4.9.3 and is deprecated now.

see cDirHandler
recursiveRmdir($dirname)This method was moved to cDirHandler class with version 4.9.3 and is deprecated now.

see 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

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

The call of the method above removes the index.php file.

 

 

 

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

rename('/var/www/index.php','/var/www/index.html');

The call of the method above renames the index.php file to index.html.

setDefaultDirPerms($pathname)This method was moved to cDirHandler class with version 4.9.3 and is deprecated now. see 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

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

The call of the method above removes the content of the index.php file.

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

write('/var/www/index.php','hello world!');

The call of the method above writes the string 'hello world!' in the index.php file.

 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

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

The call of the method above returns true if the index.php file is writeable, otherwise false.

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

writeLine('/var/www/index.php','hello world!');

The call of the method above returns writes the line 'hello world!' to the index.php file.