Tuskfish API
  • Package
  • Class

Packages

  • content
  • core
  • database
  • installation
  • security
  • user
  • utilities

Classes

  • TfishAncestralObject
  • TfishAngryTree
  • TfishCache
  • TfishFileHandler
  • TfishLogger
  • TfishPreference
  • TfishPreferenceHandler

Functions

  • tfish_autoload

Class TfishFileHandler

Tuskfish file handler class.

Provides methods for handling common file operations. In some cases, sensitive operations are restricted to a particular directory (for example, file uploads).

Package: core
Copyright: Simon Wilkinson 2013-2017 (https://tuskfish.biz)
License: GNU General Public License (GPL) V2
Author: Simon Wilkinson simon@isengard.biz
Version: Release: 1.0
Since: 1.0
Located at trust_path/libraries/tuskfish/class/TfishFileHandler.php

Methods summary

public static array
# allowedAudioMimetypes( )

Returns an array of audio mimetypes that are permitted for content objects.

Returns an array of audio mimetypes that are permitted for content objects.

Note that ogg audio files should use the .oga extension, although the legacy .ogg extension is still acceptable, although it must no longer be used for video files.

Returns

array
Array of permitted audio mimetypes in file extension => mimetype format.
public static array
# allowedImageMimetypes( )

Returns an array of image mimetypes that are permitted for content objects.

Returns an array of image mimetypes that are permitted for content objects.

Returns

array
Array of permitted image mimetypes in file extension => mimetype format.
public static array
# allowedVideoMimetypes( )

Returns an array of video mimetypes that are permitted for upload.

Returns an array of video mimetypes that are permitted for upload.

Note that ogg video files must use the .ogv file extension. Please do not use .ogg for video files as this practice has been deprecated in favour of .ogv. While .ogg is still in wide use it is now presumed to refer to audio files only.

Returns

array
Array of permitted video mimetypes in file extension => mimetype format.
public static boolean
# appendFile( string $path, string $contents )

Append a string to a file.

Append a string to a file.

Do not set the $path using untrusted data sources, such as user input.

Parameters

$path
Path to the target file.
$contents
Content to append to the target file.

Returns

boolean
True on success false on failure.
public static boolean
# clearDirectory( string $path )

Deletes the contents of a specific directory, subdirectories are unaffected.

Deletes the contents of a specific directory, subdirectories are unaffected.

Do not set the $path using untrusted data sources, such as user input.

Parameters

$path
Path to the target directory.

Returns

boolean
True on success false on failure.
public static boolean
# deleteDirectory( string $path )

Destroys a directory and all contents recursively relative to the data_file directory.

Destroys a directory and all contents recursively relative to the data_file directory.

Do not set the $path using untrusted data sources, such as user input.

Parameters

$path
Path relative to data_file directory.

Returns

boolean
True on success, false on failure.
public static boolean
# deleteFile( string $path )

Destroys an individual file in the data_file directory.

Destroys an individual file in the data_file directory.

Do not set the $path using untrusted data sources, such as user input.

Parameters

$path
Path relative to the data_file directory.

Returns

boolean
True on success, false on failure.
public static array
# getPermittedUploadMimetypes( )

Returns an array of mimetypes that are permitted for upload to the media directory.

Returns an array of mimetypes that are permitted for upload to the media directory.

NOTE: Adding HTML to this list would be a BAD IDEA, as such files can include PHP code, although uploaded files have execution permissions removed and are stored outside of the web root in order to prevent direct access by browser.

Returns

array
Array of permitted mimetypes as file extensions.
public static array
# getTypeMimetypes( string $type )

Returns an array of permitted extensions/mimetypes for a given content type.

Returns an array of permitted extensions/mimetypes for a given content type.

Parameters

$type
The type (class) of content object.

Returns

array
Array of mimetypes as extension => mimetype pairs.
public static boolean
# sendDownload( integer $id, string $filename = '' )

Initiate streaming of a downloadable media file associated with a content object.

Initiate streaming of a downloadable media file associated with a content object.

DOES NOT WORK WITH COMPRESSION ENABLED IN OUTPUT BUFFER. This method acts as an intermediary to provide access to uploaded file resources that reside outside of the web root, while concealing the real file path and name. Use this method to provide safe user access to uploaded files. If anything nasty gets uploaded nobody will be able to execute it directly through the browser.

Parameters

$id
ID of the associated content object.
$filename

An alternative name (rename) for the file you wish to transfer, excluding extension.

Returns

boolean
True on success, false on failure.
public static string|boolean
# uploadFile( string $filename, string $fieldname )

Upload a file to the uploads/image or uploads/media directory and set permissions to 644.

Upload a file to the uploads/image or uploads/media directory and set permissions to 644.

Parameters

$filename
Filename.
$fieldname
Name of form field associated with this upload ('image' or 'media').

Returns

string|boolean
Filename on success, false on failure.
Tuskfish API API documentation generated by ApiGen