欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Symfony\Component\HttpFoundation\File\UploadedFile 有大用

Symfony API

class UploadedFile extends File

A file uploaded through a form.

 

Methods

 __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.

 
string|nullguessExtension()

Returns the extension based on the mime type.

from File
string|nullgetMimeType()

Returns the mime type of the file.

from File
stringgetExtension()

Returns the extension of the file.

from File
Filemove(string $directory, string $name = null)

Moves the file to a new location.

 
string|nullgetClientOriginalName()

Returns the original file name.

 
stringgetClientOriginalExtension()

Returns the original file extension

 
string|nullgetClientMimeType()

Returns the file mime type.

 
string|nullguessClientExtension()

Returns the extension based on the client mime type.

 
integer|nullgetClientSize()

Returns the file size.

 
integergetError()

Returns the upload error.

 
BooleanisValid()

Returns whether the file was uploaded successfully.

 
static intgetMaxFilesize()

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

 

Details

 

at line 92
public __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$pathThe full temporary path to the file
string$originalNameThe original file name
string$mimeTypeThe type of the file as provided by PHP
integer$sizeThe file size
integer$errorThe error constant of the upload (one of PHP's UPLOADERRXXX constants)
Boolean$testWhether the test mode is active

Exceptions

FileExceptionIf file_uploads is disabled
FileNotFoundExceptionIf the file does not exist

 

in File at line 62
public string|null guessExtension()

Returns the extension based on the mime type.

If the mime type is unknown, returns null.

This method uses the mime type as guessed by getMimeType() to guess the file extension.

Return Value

string|nullThe guessed extension or null if it cannot be guessed

See also

getMimeType() 

 

in File at line 83
public string|null getMimeType()

Returns the mime type of the file.

The mime type is guessed using a MimeTypeGuesser instance, which uses finfo(), mimecontenttype() and the system binary "file" (in this order), depending on which of those are available.

Return Value

string|nullThe guessed mime type (i.e. "application/pdf")

See also

MimeTypeGuesser 

 

in File at line 99
public string getExtension()

Returns the extension of the file.

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

Return Value

stringThe extension

 

at line 236
public File move(string $directory, string $name = null)

Moves the file to a new location.

 

Parameters

string$directoryThe destination folder
string$nameThe new file name

Return Value

FileA File object representing the new file

Exceptions

FileExceptionif, for any reason, the file could not have been moved

 

at line 117
public string|null getClientOriginalName()

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.

Return Value

string|nullThe original name

 

at line 130
public string getClientOriginalExtension()

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.

Return Value

stringThe extension

 

at line 150
public string|null getClientMimeType()

Returns the file mime type.

The client mime type is extracted from the request from which the file was uploaded, so it should not be considered as a safe value.

For a trusted mime type, use getMimeType() instead (which guesses the mime type based on the file content).

Return Value

string|nullThe mime type

See also

getMimeType 

 

at line 172
public string|null guessClientExtension()

Returns the extension based on the client mime type.

If the mime type is unknown, returns null.

This method uses the mime type as guessed by getClientMimeType() to guess the file extension. As such, the extension returned by this method cannot be trusted.

For a trusted extension, use guessExtension() instead (which guesses the extension based on the guessed mime type for the file).

Return Value

string|nullThe guessed extension or null if it cannot be guessed

See also

guessExtension() 
getClientMimeType() 

 

at line 190
public integer|null getClientSize()

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.

Return Value

integer|nullThe file size

 

at line 205
public integer getError()

Returns the upload error.

If the upload was successful, the constant UPLOADERROK is returned. Otherwise one of the other UPLOADERRXXX constants is returned.

Return Value

integerThe upload error

 

at line 217
public Boolean isValid()

Returns whether the file was uploaded successfully.

 

Return Value

BooleanTrue if the file has been uploaded with HTTP and no error occurred.

 

at line 263
static public int getMaxFilesize()

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

 

Return Value

intThe maximum size of an uploaded file in bytes


普通分类: