This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

General File Helper Functions

The following functions are useful for any file (and not concrete5-specific)

Loading the Helper

$fh = Loader::helper(‘file’);


$files = $fh->getDirectoryContents($path, $ignoreFilesArray = array()

Returns an array of files found in directory $path, ignoring any filenames found in $ignoreFilesArray, and any that begin with a dot.

$r = $fh->unfilename($filename)

Removes the extension of a filename, unhandles it.

print $fh->unfilename(‘my_custom_template.php’); // outputs “My Custom Template” 

$fh->copyAll($source, $target, $mode = ‘0777’)

Recursively copies all items in the source directory to the target directory.


Takes a path to a file and sends it to the browser, streaming it, and closing the HTTP connection afterwards.

$path = $fh->getTemporaryDirectory()

Returns the full path to the temporary directory.

$fh->append($filename, $content)

Adds content to a new line in a file. If a file is not there it will be created.

$fh->getContents($file, $timeout = 5)

Just a consistency wrapper for file_get_contents. Should use curl if it exists and fopen isn't allowed. Will also work with remote files/URLs.


Uses file_put_contents to clear a file.


Cleans up a filename and returns the cleaned up version.

$extension = $fh->getExtension($filename)

Returns the extension for a file name.

$filename = $fh->replaceExtension($filename, $extension)

Takes a path and replaces the files extension in that path with the specified extension.

General Image Helper Functions

The following functions are useful for working with images.

Loading the Helper

$im = Loader::helper(‘image’);


$im->create($originalPath, $newPath, $width, $height)

Creates a new image given an original path, a new path, a target width and height. Should retain file type and transparency.

$r = $im->getThumbnail($obj, $width, $height)

Returns a path to the specified item, resized to meet max width and height. $obj can either be a string (path) or a file object. Returns a PHP object with the following properties set

  • src - the relative path to the image (useful for display in browsers)
  • width - the new width of the image
  • height - the new height of the image.

$im->outputThumbnail($obj, $maxWidth, $maxHeight, $alt = null, $return = false, $crop = false)

Runs getThumbnail on the $obj argument, and prints out an IMG tag.

$im->output($obj, alt = ‘’)

Only takes a concrete5 File objects as its argument. Prints out the IMG tag for the object.

Loading Conversation