• PHP reference

CDN

class CDN extends ExtendableObject

Class CDN.

Upload and access files stored on Scholica.

Methods

__construct()

Constructor.

string upload(string $path, string $type = 'resource', string $ext = 'x', string $basename = 'Untitled', string $original_name = null, string $mime = null)

Upload a file.

Parameters

  • string $path File path or contents
  • string $type CDN key type (default: resource)
  • string $ext File extension
  • string $basename File name
  • string $original_name Original file name (used to determine extension and basename)
  • string $mime Mime type

Return Value

  • string CDN token

string|false download(string $token, string $target = null)

Download a file to local storage path.

Parameters

  • string $token
  • string $target

Return Value

  • string|false returns the file path of the downloaded file on success, otherwise false

boolean compareWithLocalFile(string $cdn_token, string $local_filename)

Compares an uploaded file with a local file, returns true if the files have equal contents.

Parameters

  • string $cdn_token
  • string $local_filename

Return Value

  • boolean

string|false get(string|object|File $token)

Get the URL from a CDN token.

Parameters

  • string|object|File $token

Return Value

  • string|false returns URL, or false if file does not exist

string|false fileName(string|object|File $token)

Get the original filename from a CDN token.

Parameters

  • string|object|File $token

Return Value

  • string|false returns filename, or false if file does not exist

string thumbnail(string|object|File $token, integer $width = 320, boolean $crop = true)

Get the URL of the thumbnail from a CDN token.

Parameters

  • string|object|File $token
  • integer $width Desired width of thumbnail, default = 320
  • boolean $crop Whether to crop the thumbnail to be square, default true

Return Value

  • string Returns image URL

static string|false getURL(string $token)

Get the URL from a CDN token.

Parameters

  • string $token

Return Value

  • string|false returns URL, or false if file does not exist

See also

  • CDN::get()

static string getThumbnail(string $token, integer $width = 320, boolean $crop = true)

Get the URL of the thumbnail from a CDN token.

Parameters

  • string $token
  • integer $width Desired width of thumbnail, default = 320
  • boolean $crop Whether to crop the thumbnail to be square, default true

Return Value

  • string Returns image URL

See also

  • CDN::thumbnail()

static string|false getFileName(string $token)

Get the original filename from a CDN token.

Parameters

  • string $token

Return Value

  • string|false returns filename, or false if file does not exist

See also

  • CDN::fileName()

static string|false getExtension(string $token)

Get the file extension from a CDN token.

Parameters

  • string $token

Return Value

  • string|false returns extension, or false if file does not exist

See also

  • CDN::get_extension()

string get_type(string $token, boolean $any = false)

Get file type. Note that this function only returns the file type of files known to Scholica, and that it returns uppercase file extensions.

For unknown file extensions, this method returns file (note: lowercase). For getting the extension of any file type, see get_extension().

Parameters

  • string $token
  • boolean $any

Return Value

  • string

string|null get_extension(string $token)

Get the extension of a file, based on the filename of that file. If the file does not have an extension, this returns null.

Parameters

  • string $token

Return Value

  • string|null

boolean can_preview(string $token)

Whether file can be previewed online.

Files have to have one of the following extensions and may not be larger than 25 MB (probably won't load then).

Parameters

  • string $token

Return Value

  • boolean

boolean is_image(string $token)

Whether the file is an image (.jpg, .jpeg, .png or .gif). Note that this function returns false for any image files of a type that can't generally be previewed in a browser (i.e. .bmp, .psd).

Parameters

  • string $token

Return Value

  • boolean

string get_name(string $token)

Get the file basename, i.e. the filename without path information.

Parameters

  • string $token

Return Value

  • string

Inherited from ExtendableObject

final static ExtendableObject instance()

Get instance.

Return Value

final static boolean hasInstance()

Check whether there is an instance of this class available.

Return Value

  • boolean

final boolean extension($extension)

Call class method, if it exists.

Parameters

  • $extension

Return Value

  • boolean