Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cApiPathresolveCacheHelper
  • cArray
  • cArticleCollector
  • cDirHandler
  • cFileHandler
  • cHTMLInputSelectElement
  • cIterator
  • cString
  • cStringMultiByteWrapper
  • cZipArchive
  • UI_Config_Table
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class cFileHandler

Class for file handling. Provides functions for dealing with files.

Package: Core\Util
Copyright: four for business AG <www.4fb.de>
License: http://www.contenido.org/license/LIZENZ.txt
Author: Mischa Holz
Located at classes/class.filehandler.php
Methods summary
public static boolean
# create( string $filename, string $content = '' )

Creates a new file

Creates a new file

Parameters

$filename
string
$filename the name and path of the new file
$content
string
$content [optional] content of the new file

Returns

boolean
true on success. Otherwise false.

Throws

cInvalidArgumentException
public static string|boolean
# read( string $filename, integer $length = 0, integer $offset = 0, boolean $reverse = false )

Reads bytes from a file

Reads bytes from a file

Parameters

$filename
string
$filename the name and path of the file
$length
integer
$length [optional] the number of bytes to read.
$offset
integer
$offset [optional] this will be the first byte which is read.
$reverse
boolean
$reverse [optional] if true, the function will start from the back of the file.

Returns

string|boolean
On success it returns the bytes which have been read. Otherwise false.

Throws

cInvalidArgumentException
if the file with the given filename does not exist
public static string|array|boolean
# readLine( string $filename, integer $lines = 0, integer $lineoffset = 0 )

Reads a file line by line

Reads a file line by line

Parameters

$filename
string
$filename the name and path of the file
$lines
integer
$lines [optional] the number of lines to be read.
$lineoffset
integer
$lineoffset [optional] this will be the first line which is read.

Returns

string|array|boolean
If one line was read the function will return it. If more than one line was read the function will return an array containing the lines. Otherwise false is returned

Throws

cInvalidArgumentException
if the file with the given filename does not exist
public static boolean
# write( string $filename, string $content, boolean $append = false )

Writes data to a file

Writes data to a file

Parameters

$filename
string
$filename the name and path of the file
$content
string
$content the data which should be written
$append
boolean
$append [optional] if true the data will be appended to the file.

Returns

boolean
true on success, false otherwise

Throws

cInvalidArgumentException
public static boolean
# writeLine( string $filename, string $content, boolean $append = false )

Writes a line to a file (this is similar to cFileHandler::write($filename, $data."\n", $apppend)

Writes a line to a file (this is similar to cFileHandler::write($filename, $data."\n", $apppend)

Parameters

$filename
string
$filename the name and path to the file
$content
string
$content the data of the line
$append
boolean
$append [optional] if true the data will be appended to file.

Returns

boolean
true on success, false otherwise

Throws

cInvalidArgumentException

See

cFileHandler::write($filename, $content, $append)
public static boolean
# exists( string $filename )

Checks if a file or a directory exists

Checks if a file or a directory exists

Parameters

$filename
string
$filename the name and path of the file or to the directory

Returns

boolean
true if the file or the directory exists.
public static boolean
# isFile( string $filename )

Checks if a file exists and is not a directory.

Checks if a file exists and is not a directory.

Parameters

$filename
string
$filename the name and path of the file

Returns

boolean
true if the file exists and is not a directory
public static boolean
# writeable( string $filename )

Checks if the file is writable for the PHP user

Checks if the file is writable for the PHP user

Parameters

$filename
string
$filename the name and path of the file

Returns

boolean
true if the file can be written
public static boolean
# readable( string $filename )

Checks if a file is readable for the PHP user

Checks if a file is readable for the PHP user

Parameters

$filename
string
$filename the name and path of the file

Returns

boolean
true if the file is readable

Throws

cInvalidArgumentException
if the file with the given filename does not exist
public static boolean
# remove( string $filename )

Removes a file from the filesystem

Removes a file from the filesystem

Parameters

$filename
string
$filename the name and path of the file

Returns

boolean
true on success

Throws

cInvalidArgumentException
if the file with the given filename does not exist
public static boolean
# truncate( string $filename )

Truncates a file so that it is empty

Truncates a file so that it is empty

Parameters

$filename
string
$filename the name and path of the file

Returns

boolean
true on success

Throws

cInvalidArgumentException
if the file with the given filename does not exist
public static boolean
# move( string $filename, string $destination )

Moves a file

Moves a file

Parameters

$filename
string
$filename the name of the source file
$destination
string
$destination the destination. Note that the file can also be renamed in the process of moving it

Returns

boolean
true on success

Throws

cInvalidArgumentException
if the file with the given filename does not exist
public static boolean
# rename( string $filename, string $new_filename )

Renames a file

Renames a file

Parameters

$filename
string
$filename the name and path of the file
$new_filename
string
$new_filename the new name of the file

Returns

boolean
true on success

Throws

cInvalidArgumentException
if the file with the given filename does not exist
public static boolean
# copy( string $filename, string $destination )

Copies a file

Copies a file

Parameters

$filename
string
$filename the name and path of the file
$destination
string
$destination the destination. Note that existing files get overwritten

Returns

boolean
true on success

Throws

cInvalidArgumentException
if the file with the given filename does not exist
public static boolean
# chmod( string $filename, integer $mode )

Changes the file permissions

Changes the file permissions

Parameters

$filename
string
$filename the name and path of the file
$mode
integer
$mode the new access mode : php chmod needs octal value

Returns

boolean
true on success

Throws

cInvalidArgumentException
if the file with the given filename does not exist
public static array
# info( string $filename )

Returns an array containing information about the file. Currently following elements are in it: 'size' - the file size (in byte) 'atime' - the time the file was last accessed (unix timestamp) 'ctime' - time the file was created (unix timestamp) 'mtime' - time the file was last modified (unix timestamp) 'perms' - permissions of the file represented in 4 octal digits 'extension' - the file extension or '' if there's no extension 'mime' - the mime type of the file

Returns an array containing information about the file. Currently following elements are in it: 'size' - the file size (in byte) 'atime' - the time the file was last accessed (unix timestamp) 'ctime' - time the file was created (unix timestamp) 'mtime' - time the file was last modified (unix timestamp) 'perms' - permissions of the file represented in 4 octal digits 'extension' - the file extension or '' if there's no extension 'mime' - the mime type of the file

Parameters

$filename
string
$filename the name and path to the file

Returns

array
Returns an array containing information about the file

Throws

cInvalidArgumentException
if the file with the given filename does not exist
public static string
# getExtension( string $basename )

Returns the extension of passed filename

Returns the extension of passed filename

Parameters

$basename
string
$basename

Returns

string
public static integer
# getDefaultPermissions( )

Determines the default permissions for new files. These can be configured using the setting "default_perms/file" in "data/config/<ENV>/config.misc.php". If no configuration can be found 0664 is assumed.

Determines the default permissions for new files. These can be configured using the setting "default_perms/file" in "data/config/<ENV>/config.misc.php". If no configuration can be found 0664 is assumed.

Returns

integer
public static boolean
# setDefaultPermissions( string $filename )

Sets the default permissions for the given file.

Sets the default permissions for the given file.

Parameters

$filename
string
$filename the name of the file

Returns

boolean
true on success or false on failure

Throws

cInvalidArgumentException
public static boolean
# setDefaultFilePerms( string $filename )

Sets the default permissions for the given file.

Sets the default permissions for the given file.

Deprecated

use setDefaultPermissions() instead

Parameters

$filename
string
$filename the name of the file

Returns

boolean
true on success or false on failure

Throws

cInvalidArgumentException
public static boolean
# validateFilename( string $filename, boolean $notifyAndExitOnFailure = true )

Validates the given filename.

Validates the given filename.

Parameters

$filename
string
$filename the filename to validate
$notifyAndExitOnFailure
boolean
$notifyAndExitOnFailure [optional] if set, function will show a notification and will exit the script

Returns

boolean
true if the given filename is valid, false otherwise

Throws

cInvalidArgumentException
public static boolean
# fileNameIsDot( string $fileName )

Check if given filename is either '.' or '..'.

Check if given filename is either '.' or '..'.

Parameters

$fileName
string
$fileName

Returns

boolean
public static boolean
# fileNameBeginsWithDot( string $fileName )

Check if file name begins with a period.

Check if file name begins with a period.

Parameters

$fileName
string
$fileName

Returns

boolean
Constants summary
integer DEFAULT_MODE 0664
#

default permissions for new files

default permissions for new files

See

CON-2770
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0