API Documentation for: 1.0.1
Show:

Uploader Class

Namespace: Canteen\Media

The Uploader is generalized way to upload any number of file types. Located in the namespace Canteen\Media.

Constructor

Uploader

(
  • inputName
  • uploadDir
  • mimeTypes
  • fileExts
  • [filename='']
)

Parameters:

  • inputName String

    The name of the input to check for

  • uploadDir String

    The upload direction location

  • mimeTypes Array

    The acceptable mime types

  • fileExts Array

    The collection of valid file types

  • [filename=''] String optional

    Optionally specify a filename

Methods

fixFilename

(
  • file
)
String private

Fix the file name by removing non-valid characters

Parameters:

  • file String

    The input file name

Returns:

String:

The sanitized filename

getExtension

() String

Get the file extension

Returns:

String:

The file extension

initCheck

(
  • overwrite
)
Boolean private

Run the initial check for the file type and extensions

Parameters:

  • overwrite Boolean

    If we can overwrite the file

Returns:

Boolean:

If the check was successful

postCheck

() Boolean private

Post check after upload to make sure everything went well

Returns:

Boolean:

True if everything went well

success

() Boolean

If the upload was a success

Returns:

Boolean:

If the upload was a success

upload

(
  • [overwrite=false]
  • [maxSize=Uploader::DEFAULT_SIZE]
)

Upload the file

Parameters:

  • [overwrite=false] Boolean optional

    If we should overwrite the existing file

  • [maxSize=Uploader::DEFAULT_SIZE] Int optional

    The maximum file size in bytes (default 1MB)

Properties

_fileExts

Array private

Acceptable file extensions

_mimeTypes

Array private

Acceptable mime types

DEFAULT_SIZE

Int final static

The default max file size in bytes

Default: 1048576

fileExt

String protected

The file extension

filename

String

The name of the file

filePath

String protected

The path to the target output file

filesize

Int protected

The size of the uploaded file

fileType

String protected

The type of file (mime type)

maxSize

Int protected

The maximum size of the file upload in bytes

memoryLimit

Int protected

PHP's memory limit in bytes

success

Boolean

If the upload was successful

tempName

String protected

The temporary upload file name

uploadDir

String protected

The upload location

uploadResult

Boolean protected

If the uploaded file was moved