Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • Apc
  • App
  • ArrayCache
  • Asset
  • Base
  • BaseCache
  • BaseController
  • Bicache
  • Cache
  • Config
  • Cookie
  • Couchbase
  • Counter
  • Db
  • DbCache
  • E
  • Env
  • Error
  • FileCache
  • Gravatar
  • Http
  • Lock
  • Logger
  • Memcache
  • Memcached
  • MongoCache
  • Password
  • PhpError
  • PhpFileCache
  • Pinyin
  • Record
  • Redis
  • Request
  • Response
  • Router
  • SafeUrl
  • Session
  • Soap
  • T
  • Ua
  • Upload
  • Url
  • Uuid
  • Validate
  • View
  • WeChatApp
  • Wei
  • Overview
  • Namespace
  • Class

Class Upload

A service that handles the uploaded files

Wei\Base
Extended by Wei\Validator\BaseValidator
Extended by Wei\Validator\File
Extended by Wei\Validator\Image
Extended by Wei\Upload
Namespace: Wei
Author: Twin Huang twinhuang@qq.com
Located at Upload.php
Methods summary
public
# __construct( array $options = array() )

Constructor

Constructor

Parameters

$options

Throws

InvalidArgumentException
When option "wei" is not an instance of "Wei\Wei"

Overrides

Wei\Base::__construct()
public boolean
# __invoke( string|array $field = null, array $options = array() )

Upload a file

Upload a file

Parameters

$field
The name of file input or options of wei
$options
The options of wei

Returns

boolean

Overrides

Wei\Validator\File::__invoke()
protected boolean
# saveFile( array $uploadedFile )

Save uploaded file to upload directory

Save uploaded file to upload directory

Parameters

$uploadedFile

Returns

boolean
public string
# getFile( )

Returns the uploaded file path

Returns the uploaded file path

Returns

string
public
# setDir( string $dir )

Set upload directory

Set upload directory

Parameters

$dir

Returns


$this
public string
# getDir( )

Returns upload directory

Returns upload directory

Returns

string
protected string
# getIniSize( string $name )

Returns a human readable file size (e.g. 1.2MB, 10KB), which recive from the ini configuration

Returns a human readable file size (e.g. 1.2MB, 10KB), which recive from the ini configuration

Parameters

$name
The name of ini configuration

Returns

string
protected boolean
# isUploadedFile( string $file )

Check if the file was uploaded via HTTP POST, if $this->unitTest is enable, it will always return true

Check if the file was uploaded via HTTP POST, if $this->unitTest is enable, it will always return true

Parameters

$file

Returns

boolean
protected boolean
# moveUploadedFile( string $from, string $to )

Moves an uploaded file to a new location, if $this->unitTest is enable, it will use copy function instead

Moves an uploaded file to a new location, if $this->unitTest is enable, it will use copy function instead

Parameters

$from
The uploaded file name
$to
The destination of the moved file.

Returns

boolean
Methods inherited from Wei\Validator\Image
doValidate()
Methods inherited from Wei\Validator\File
convertToArray(), fromBytes(), getExt(), getMimeType(), inMimeType(), setExcludeExts(), setExcludeMimeTypes(), setExts(), setMaxSize(), setMimeTypes(), setMinSize(), toBytes()
Methods inherited from Wei\Validator\BaseValidator
addError(), getErrors(), getFirstMessage(), getJoinedMessage(), getMessages(), getName(), hasError(), isString(), isValid(), loadTranslationMessages(), setMessages(), setName(), storeOption()
Methods inherited from Wei\Base
__call(), __get(), getOption(), setOption()
Magic methods inherited from Wei\Validator\BaseValidator
t()
Properties summary
protected string $postSizeMessage

Seems that the total post data size is too large

Seems that the total post data size is too large

Link

http://php.net/manual/en/ini.core.php#ini.post-max-size
# 'No file uploaded or the total file size is too large, allowed maximum size is %postMaxSize%'
protected string $noFileMessage

The uploaded file array do not contain the key "$this->field", or error code not available

The uploaded file array do not contain the key "$this->field", or error code not available

# 'No file uploaded, please select a file to upload'
protected string $formLimitMessage
# '%name% is larger than the MAX_FILE_SIZE value in the HTML form'
protected string $partialMessage
# '%name% was partial uploaded, please try again'
protected string $noTmpDirMessage
# 'The temporary upload directory is missing'
protected string $cantWriteMessage
# 'Cannot write %name% to disk'
protected string $extensionMessage
# 'File upload stopped by extension'
protected string $notUploadedFileMessage
# 'No file uploaded'
protected string $cantMoveMessage
# 'Cannot move uploaded file'
protected string $name

The name for error message

The name for error message

# 'file'
protected string $field

The name defined in the file input, if it's not specified, use the first key in upload files array (equals to $_FILES on default)

The name defined in the file input, if it's not specified, use the first key in upload files array (equals to $_FILES on default)

#
protected string $dir

The directory to save file, automatic create it if not exist

The directory to save file, automatic create it if not exist

# 'uploads'
protected string $fileName

The custom file name (without extension) as upload file name to save

The custom file name (without extension) as upload file name to save

#
protected boolean $isImage

Whether check if the upload file is valid image or not

Whether check if the upload file is valid image or not

You can specify any one of the following options to enable image detect * maxWidth * maxHeight * minWidth * minHeight

# false
protected boolean $overwrite

Whether overwrite existing file, if set to false, the uploader will add a number between file name and extension, like file-1.jpg, file-2.jpg

Whether overwrite existing file, if set to false, the uploader will add a number between file name and extension, like file-1.jpg, file-2.jpg

# false
protected boolean $unitTest

Whether in unit test mode

Whether in unit test mode

# false
protected string $postMaxSize

The max size of post data, for $this->postMaxSize

The max size of post data, for $this->postMaxSize

#
Properties inherited from Wei\Validator\Image
$height, $heightTooBigMessage, $heightTooSmallMessage, $maxHeight, $maxWidth, $minHeight, $minWidth, $notDetectedMessage, $width, $widthTooBigMessage, $widthTooSmallMessage
Properties inherited from Wei\Validator\File
$excludeExts, $excludeExtsMessage, $excludeMimeTypes, $excludeMimeTypesMessage, $ext, $exts, $extsMessage, $file, $magicFile, $maxSize, $maxSizeMessage, $maxSizeString, $mimeType, $mimeTypeNotDetectedMessage, $mimeTypes, $mimeTypesMessage, $minSize, $minSizeMessage, $minSizeString, $negativeMessage, $notFoundMessage, $originFile, $size, $sizeString, $units
Properties inherited from Wei\Validator\BaseValidator
$errors, $negative, $notStringMessage, $validator
Properties inherited from Wei\Base
$providers, $wei
Magic properties summary
public Wei\Request $request

The HTTP request wei

Magic properties inherited from Wei\Validator\BaseValidator
$t
Wei Framework API documentation generated by ApiGen