Methods for working with files, including images
This is the code documentation for the SproutCMS project
Search documentation |
class FileMethods for working with files, including images
Functions
public absUrlstring File::absUrl ( string $filename ); Returns the public URL for a given file, including domain. private backendFilesBackend File::backend ( ); Return the backend library to use for many file operations public base64Thumbfalse|array File::base64Thumb ( string $file_path , int $width , int $height ); Generates a cropped, base-64 encoded thumbnail of an image public calculateResizeRamvoid File::calculateResizeRam ( array $dimensions ); Will we have enough RAM to do the resizes? public checkFileContentsExtensionboolean|null File::checkFileContentsExtension ( string $filename , string $ext ); Checks file contents match the extension public cleanupLocalCopyunknown File::cleanupLocalCopy ( string $temp_filename ); Remove a local copy of a file Call this once you're done with the local copy public createDefaultSizesvoid File::createDefaultSizes ( string $filename [, string $specific_size ] ); Create default image sizes as per the config parameter 'file.image_transformations' The transformed files get saved onto the server. If any of the transformations in a transform-group fails, the whole group will fail and the file will not be saved. public createLocalCopystring File::createLocalCopy ( string $filename ); Create a copy of the file in a temporary directory. Don't forget to File::destroy_local_copy($temp_filename) when you're done! public createSizebool File::createSize ( string $filename , string $size [, string $force_ext ] ); Create a resized version of the specified file at a given size. The size is specified the same as the file/resize method (rXXXxYYY or cXXXxYYY) The output filename will be basename.size.ext The files can be used with `size_url` or `get_resize_filename` on the front-end. public deletebool File::delete ( string $filename ); Delete a file If the file is an image, any resized variants (e.g. 'small', 'medium' etc.) are deleted too public deleteCachevoid File::deleteCache ( string $filename ); Delete cached versions of a file public downloadvoid File::download ( string $filename [, string $download_name ] ); Prompts a user to download a file, and terminates the script Sets all the right headers and stuff, doesn't set caching/expires/etc headers though. public existsbool File::exists ( string $filename ); Returns TRUE if the file exists, and FALSE if it does not public filenameMakeSanestring File::filenameMakeSane ( string $filename ); Make a filename sane - strip lots of characters which create problems public findUsageunknown File::findUsage ( string $filename ); Searches the whole database to find all records in all columns which contain a given filename. The search looks in VARCHAR columns with more than 200 chars (exact match) and in TEXT columns (contains match) Return value is an array of matches, in the format: [0] => table [1] => record id [2] => record name, if available public getDetailsarray File::getDetails ( int $id ); Gets the details of a file using its id. Uses a prepared statement for speed when doing repeated queries. N.B. If the file entry doesn't exist, a reference to 'missing.png' is returned public getExtstring File::getExt ( string $filename ); Gets the (final) extension from a file name, in lowercase public getNoextstring File::getNoext ( string $original ); For a given file, returns the name without an ext public getResizeFilenamestring File::getResizeFilename ( string $original , string $size_name [, string $force_ext ] ); For a given file, returns the filename to use to retrieve a resized version of the file public getStringstring File::getString ( string $filename ); Returns file content as a string. Basically the same as file_get_contents public getTypeint File::getType ( string $filename ); Determines the file type from a file name by examining its extension public globunknown File::glob ( string $mask ); Returns all files which match the specified mask. I have a feeling this returns other sizes (e.g. .small) as well - which may not be ideal. public humanSizestring File::humanSize ( int $size ); Converts a file size, in bytes, into a human readable form (with trailing kb, mb, etc) public imageSizearray File::imageSize ( string $filename ); Returns the size of an image, or false on failure. Output format is the same as getimagesize, but will be at a minimum: [0] => width, [1] => height, [2] => type public lookupReplacementNamestring File::lookupReplacementName ( string $filename ); Checks the database for an updated name for a file. This only works for full-sized images, e.g. 123_example.jpg, not 123_example.small.jpg public lookupReplacementUrlstring File::lookupReplacementUrl ( string $filename ); Checks the database for an updated URL path for a file. I.e. a file which has been replaced by the admin 'replace file' tool. public mimetypestring File::mimetype ( string $filename ); Return the mimetype for a given filename. Only uses the extension - doesn't actually check the file If you need deep checking, take a look at File::checkFileContentsExtension If the extension is unrecognised, returns 'application/octet-stream'. public mimetypeExtendednull|string File::mimetypeExtended ( string $path ); Get the content-type of a file using magic mime. This is _NOT_ limited to the whitelist of mime types described in the Constants. Use this with care. Note mime_content_type() inspects file contents and can't always determine css/js files correctly, this is a hack fix for that. https://stackoverflow.com/a/17736797/7694753 public moveUploadbool File::moveUpload ( string $src , string $filename ); Moves an uploaded file into the repository. Returns TRUE on success, FALSE on failure. public mtimeint File::mtime ( string $filename ); Returns the modified time, in unix timestamp format, of the specified file public parseSizeStringarray File::parseSizeString ( Size $str ); Parse the size string used in file/resize and some helpers. Syntax: [crm]{number}x{number}(-[lcr][tcb])(~{number}) Type Width Height Crop X Y Quality Returns an array. [0] type, either 'r', 'c' or 'm' r = resize, up or down, try to fill the area requested c = crop, resulting file will always be the width and height requested m = resize down only [1] width [2] height [3] x position, 'left', 'center' or 'right' [4] y position, 'top', 'center' or 'bottom' [5] jpeg quality, 0 = worst, 100 = best Returns an empty array on error (so you can use list() safely) public postUploadProcessingvoid File::postUploadProcessing ( string $filename , int $file_id , int $file_type ); Do post-processing after a file upload public putExistingbool File::putExisting ( string $filename , string $existing ); Saves file content from an existing file public putStreambool File::putStream ( string $filename , resource $stream ); Saves file content from a stream. Basically just fopen/stream_copy_to_stream/fclose public putStringbool File::putString ( string $filename , string $content ); Saves file content as a string. Basically the same as file_put_contents public readfileunknown File::readfile ( string $filename ); This is the equivalent of the php readfile function public relUrlstring File::relUrl ( string $filename ); Returns the relative public URL for a given file. Doesn't contain ROOT/ or domain. Use for content areas. public replaceSetarray File::replaceSet ( string $session_key , string $field_name , array $exts , string $prefix ); Replaces a set of files to be stored in a single field; this acts as a backend for Fb::chunkedUpload Files are saved as '{prefix}{num}.{ext}', with 'num' starting at 1 public resizeUrlstring File::resizeUrl ( int $id , string $size ); Returns the relative URL for a dynamically resized image. Size formatting is as per File::parseSizeString, e.g. c400x300 public sizeint File::size ( string $filename ); Returns the size, in bytes, of the specified file public sizeUrlstring File::sizeUrl ( int $id , string $size_name [, string $force_ext [, bool $create_if_missing ]] ); Gets the relative URL for a fixed or dynamically resized image public touchbool File::touch ( mixed $filename ); Sets access and modification time of file public urlstring File::url ( string $filename ); Returns the public URL for a given file. Does not include domain. |
Powered by Pelzini, version 0.9.0 |
Documentation is made available under the
GNU Free Documentation License 1.2. Generated: Monday, 3rd April, 2023 at 02:59 pm |