PHP Класс ImageManager

Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$config Configuration array.
$dirs Array of directory information.

Открытые методы

Метод Описание
ImageManager ( array $config ) Constructor. Create a new Image Manager instance.
_delDir ( string $relative ) : boolean Delete directories recursively.
_delFile ( string $relative ) : boolean Delete the relative file, and any thumbnails.
_dirs ( string $base, string $path ) : array Recursively travese the directories to get a list of accessable directories.
_processFiles ( string $relative, array $file ) : boolean Process upload files. The file must be an uploaded file. If 'validate_images' is set to true, only images will be processed. Any duplicate file will be renamed. See Files::copyFile for details on renaming.
countFiles ( $path ) Count the number of files and directories in a given folder minus the thumbnail folders and thumbnails.
deleteDirs ( ) : boolean Delete and specified directories.
deleteFiles ( ) : boolean Delete and specified files.
getBaseDir ( ) : string Get the base directory.
getBaseURL ( ) : string Get the base URL.
getDefaultThumb ( ) : string Get the default thumbnail.
getDirs ( ) : array Get the sub directories in the base dir.
getFileURL ( string $relative ) : string Get the URL of the relative file.
getFiles ( string $path, $articleId ) : array Get all the files and directories of a relative path.
getFullPath ( string $relative ) : string Get the fullpath to a relative file.
getImageByNumber ( $articleId, $imageNumber )
getImageInfo ( string $file ) : array Get image size information.
getThumbName ( string $fullpathfile ) : string For a given image file, get the respective thumbnail filename no file existence check is done.
getThumbURL ( string $relative ) : string Similar to getThumbName, but returns the URL, base on the given base_url in config.inc.php
getThumbnail ( string $relative ) : string Get the thumbnail url to be displayed.
getTmpPrefix ( ) : string Get the tmp file prefix.
isThumb ( string $file ) : true Check if the file contains the thumbnail prefix.
isThumbDir ( string $entry ) : true Check if the given directory is a thumbnail directory.
isTmpFile ( string $file ) : boolean Check if the given file is a tmp file.
isValidBase ( )
processNewDir ( ) : boolean Create new directories.
processUploads ( ) : null Process uploaded files, assumes the file is in $_FILES['upload'] and $_POST['dir'] is set.
validRelativePath ( string $path ) : boolean Check if the given path is part of the subdirectories under the base_dir.

Описание методов

ImageManager() публичный Метод

Constructor. Create a new Image Manager instance.
public ImageManager ( array $config )
$config array configuration array, see config.inc.php

_delDir() публичный Метод

Delete directories recursively.
public _delDir ( string $relative ) : boolean
$relative string the relative path to be deleted.
Результат boolean true if deleted, false otherwise.

_delFile() публичный Метод

Delete the relative file, and any thumbnails.
public _delFile ( string $relative ) : boolean
$relative string the relative file.
Результат boolean true if deleted, false otherwise.

_dirs() публичный Метод

Recursively travese the directories to get a list of accessable directories.
public _dirs ( string $base, string $path ) : array
$base string the full path to the current directory
$path string the relative path name
Результат array of accessiable sub-directories array('path name' => 'full directory path', ...)

_processFiles() публичный Метод

Process upload files. The file must be an uploaded file. If 'validate_images' is set to true, only images will be processed. Any duplicate file will be renamed. See Files::copyFile for details on renaming.
public _processFiles ( string $relative, array $file ) : boolean
$relative string the relative path where the file should be copied to.
$file array the uploaded file from $_FILES
Результат boolean true if the file was processed successfully, false otherwise

countFiles() публичный Метод

Count the number of files and directories in a given folder minus the thumbnail folders and thumbnails.
public countFiles ( $path )

deleteDirs() публичный Метод

Delete and specified directories.
public deleteDirs ( ) : boolean
Результат boolean true if delete, false otherwise

deleteFiles() публичный Метод

Delete and specified files.
public deleteFiles ( ) : boolean
Результат boolean true if delete, false otherwise

getBaseDir() публичный Метод

Get the base directory.
public getBaseDir ( ) : string
Результат string base dir, see config.inc.php

getBaseURL() публичный Метод

Get the base URL.
public getBaseURL ( ) : string
Результат string base url, see config.inc.php

getDefaultThumb() публичный Метод

Get the default thumbnail.
public getDefaultThumb ( ) : string
Результат string default thumbnail, empty string if the thumbnail doesn't exist.

getDirs() публичный Метод

Each array element contain the relative path (relative to the base dir) as key and the full path as value.
public getDirs ( ) : array
Результат array of sub directries array('path name' => 'full directory path', ...)

getFileURL() публичный Метод

basically appends the relative file to the base_url given in config.inc.php
public getFileURL ( string $relative ) : string
$relative string a file the relative to the base_dir
Результат string the URL of the relative file.

getFiles() публичный Метод

Get all the files and directories of a relative path.
public getFiles ( string $path, $articleId ) : array
$path string relative path to be base path.
Результат array of file and path information. array(0 => array('relative'=>'fullpath',...), 1 => array('filename'=>fileinfo array(),...) fileinfo array: array('url'=>'full url', 'relative'=>'relative to base', 'fullpath'=>'full file path', 'image'=>imageInfo array() false if not image, 'stat' => filestat)

getFullPath() публичный Метод

Get the fullpath to a relative file.
public getFullPath ( string $relative ) : string
$relative string the relative file.
Результат string the full path, .ie. the base_dir + relative.

getImageByNumber() публичный Метод

public getImageByNumber ( $articleId, $imageNumber )

getImageInfo() публичный Метод

Get image size information.
public getImageInfo ( string $file ) : array
$file string the image file
Результат array of getImageSize information, false if the file is not an image.

getThumbName() публичный Метод

For a given image file, get the respective thumbnail filename no file existence check is done.
public getThumbName ( string $fullpathfile ) : string
$fullpathfile string the full path to the image file
Результат string of the thumbnail file

getThumbURL() публичный Метод

Similar to getThumbName, but returns the URL, base on the given base_url in config.inc.php
public getThumbURL ( string $relative ) : string
$relative string the relative image file name, relative to the base_dir path
Результат string the url of the thumbnail

getThumbnail() публичный Метод

If the thumbnail exists, and it is up-to-date the thumbnail url will be returns. If the file is not an image, a default image will be returned. If it is an image file, and no thumbnail exists or the thumbnail is out-of-date (i.e. the thumbnail modified time is less than the original file) then a thumbs.php?img=filename.jpg is returned. The thumbs.php url will generate a new thumbnail on the fly. If the image is less than the dimensions of the thumbnails, the image will be display instead.
public getThumbnail ( string $relative ) : string
$relative string the relative image file.
Результат string the url of the thumbnail, be it actually thumbnail or a script to generate the thumbnail on the fly.

getTmpPrefix() публичный Метод

Get the tmp file prefix.
public getTmpPrefix ( ) : string
Результат string tmp file prefix.

isThumb() публичный Метод

Check if the file contains the thumbnail prefix.
public isThumb ( string $file ) : true
$file string filename to be checked
Результат true if the file contains the thumbnail prefix, false otherwise.

isThumbDir() публичный Метод

Check if the given directory is a thumbnail directory.
public isThumbDir ( string $entry ) : true
$entry string directory name
Результат true if it is a thumbnail directory, false otherwise

isTmpFile() публичный Метод

Check if the given file is a tmp file.
public isTmpFile ( string $file ) : boolean
$file string file name
Результат boolean true if it is a tmp file, false otherwise

isValidBase() публичный Метод

public isValidBase ( )

processNewDir() публичный Метод

If in safe_mode, nothing happens.
public processNewDir ( ) : boolean
Результат boolean true if created, false otherwise.

processUploads() публичный Метод

The dir must be relative to the base_dir and exists. If 'validate_images' is set to true, only file with image dimensions will be accepted.
public processUploads ( ) : null
Результат null

validRelativePath() публичный Метод

Check if the given path is part of the subdirectories under the base_dir.
public validRelativePath ( string $path ) : boolean
$path string the relative path to be checked
Результат boolean true if the path exists, false otherwise

Описание свойств

$config публичное свойство

Configuration array.
public $config

$dirs публичное свойство

Array of directory information.
public $dirs