SymfonyComponentHttpFoundationFileUploadedFile

A file uploaded through a form.

File
vendorSymfonyComponentHttpFoundationFileUploadedFile.php
Package
Default
Class hierarchy
SplFileInfo
SymfonyComponentHttpFoundationFileUploadedFile

Tags

author

Bernhard Schussek bschussek@gmail.com

Florian Eckerstorfer florian@eckerstorfer.org

Fabien Potencier fabien@symfony.com

api

Properties

$test

$test : Boolean

Whether the test mode is activated.

Local files are used in test mode hence the code should not enforce HTTP uploads.

Type

Boolean

Tags

None found

$originalName

$originalName : string

The original name of the uploaded file.

Type

string

Tags

None found

$mimeType

$mimeType : string

The mime type provided by the uploader.

Type

string

Tags

None found

$size

$size : string

The file size provided by the uploader.

Type

string

Tags

None found

$error

$error : integer

The UPLOAD_ERR_XXX constant provided by the uploader.

Type

integer

Tags

None found

Methods

__construct()

__construct(string  $path, string  $originalName, string  $mimeType = null, integer  $size = null, integer  $error = null, Boolean  $test = false) 

Accepts the information of the uploaded file as provided by the PHP global $_FILES.

The file object is only created when the uploaded file is valid (i.e. when the isValid() method returns true). Otherwise the only methods that could be called on an UploadedFile instance are:

  • getClientOriginalName,
  • getClientMimeType,
  • isValid,
  • getError.

Calling any other method on an non-valid instance will cause an unpredictable result.

Parameters

string $path

The full temporary path to the file

string $originalName

The original file name

string $mimeType

The type of the file as provided by PHP

integer $size

The file size

integer $error

The error constant of the upload (one of PHP's UPLOAD_ERR_XXX constants)

Boolean $test

Whether the test mode is active

Throws

SymfonyComponentHttpFoundationFileExceptionFileException

If file_uploads is disabled

SymfonyComponentHttpFoundationFileExceptionFileNotFoundException

If the file does not exist

Tags

api

guessExtension()

guessExtension() : string|null

Returns the extension based on the mime type.

If the mime type is unknown, returns null.

Returns

string|null —

The guessed extension or null if it cannot be guessed

getMimeType()

getMimeType() : string|null

Returns the mime type of the file.

The mime type is guessed using the functions finfo(), mime_content_type() and the system binary "file" (in this order), depending on which of those is available on the current operating system.

Returns

string|null —

The guessed mime type (i.e. "application/pdf")

getExtension()

getExtension() : string

Returns the extension of the file.

SplFileInfo::getExtension() is not available before PHP 5.3.6

Returns

string —

The extension

move()

move(string  $directory, string  $name = null) : \Symfony\Component\HttpFoundation\File\File

Moves the file to a new location.

Parameters

string $directory

The destination folder

string $name

The new file name

Throws

SymfonyComponentHttpFoundationFileExceptionFileException

if the file has not been uploaded via Http

Returns

SymfonyComponentHttpFoundationFileFile

A File object representing the new file

Tags

api

getClientOriginalName()

getClientOriginalName() : string|null

Returns the original file name.

It is extracted from the request from which the file has been uploaded. Then is should not be considered as a safe value.

Returns

string|null —

The original name

Tags

api

getClientOriginalExtension()

getClientOriginalExtension() : string

Returns the original file extension

It is extracted from the original file name that was uploaded. Then is should not be considered as a safe value.

Returns

string —

The extension

Tags

None found

getClientMimeType()

getClientMimeType() : string|null

Returns the file mime type.

It is extracted from the request from which the file has been uploaded. Then is should not be considered as a safe value.

Returns

string|null —

The mime type

Tags

api

getClientSize()

getClientSize() : integer|null

Returns the file size.

It is extracted from the request from which the file has been uploaded. Then is should not be considered as a safe value.

Returns

integer|null —

The file size

Tags

api

getError()

getError() : integer

Returns the upload error.

If the upload was successful, the constant UPLOAD_ERR_OK is returned. Otherwise one of the other UPLOAD_ERR_XXX constants is returned.

Returns

integer —

The upload error

Tags

api

isValid()

isValid() : Boolean

Returns whether the file was uploaded successfully.

Returns

Boolean —

True if no error occurred during uploading

Tags

api

getMaxFilesize()

getMaxFilesize() : integer

Returns the maximum size of an uploaded file as configured in php.ini

Returns

integer —

The maximum size of an uploaded file in bytes

static

Tags

None found

getTargetFile()

getTargetFile(  $directory,   $name = null) 

Parameters

$directory
$name

Inherited from
SymfonyComponentHttpFoundationFileFile

Tags

None found

getName()

getName(string  $name) : string

Returns locale independent base name of the given path.

Parameters

string $name

The new file name

Returns

string —

containing

Inherited from
SymfonyComponentHttpFoundationFileFile

Tags

None found