Overview
  • Namespace
  • Class

Namespaces

  • Slim
    • Exception
    • Handlers
      • Strategies
    • Http
    • Interfaces
      • Http

Classes

  • Body
  • Cookies
  • Environment
  • Headers
  • Message
  • Request
  • RequestBody
  • Response
  • Stream
  • UploadedFile
  • Uri

Class UploadedFile

Represents Uploaded Files.

It manages and normalizes uploaded files according to the PSR-7 standard.

Slim\Http\UploadedFile implements Psr\Http\Message\UploadedFileInterface
Namespace: Slim\Http
Link: https://github.com/php-fig/http-message/blob/master/src/UploadedFileInterface.php
Link: https://github.com/php-fig/http-message/blob/master/src/StreamInterface.php
Located at Http/UploadedFile.php

Methods summary

public static array|null
# createFromEnvironment( Slim\Http\Environment $env )

Create a normalized tree of UploadedFile instances from the Environment.

Create a normalized tree of UploadedFile instances from the Environment.

Parameters

$env
The environment

Returns

array|null
A normalized tree of UploadedFile instances or null if none are provided.
public
# __construct( string $file, string|null $name = null, string|null $type = null, integer|null $size = null, integer $error = UPLOAD_ERR_OK, boolean $sapi = false )

Construct a new UploadedFile instance.

Construct a new UploadedFile instance.

Parameters

$file
The full path to the uploaded file provided by the client.
$name
The file name.
$type
The file media type.
$size
The file size in bytes.
$error
The UPLOAD_ERR_XXX code representing the status of the upload.
$sapi
Indicates if the upload is in a SAPI environment.
public Psr\Http\Message\StreamInterface
# getStream( )

Retrieve a stream representing the uploaded file.

Retrieve a stream representing the uploaded file.

This method MUST return a StreamInterface instance, representing the uploaded file. The purpose of this method is to allow utilizing native PHP stream functionality to manipulate the file upload, such as stream_copy_to_stream() (though the result will need to be decorated in a native PHP stream wrapper to work with such functions).

If the moveTo() method has been called previously, this method MUST raise an exception.

Returns

Psr\Http\Message\StreamInterface
Stream representation of the uploaded file.

Throws

RuntimeException

in cases when no stream is available or can be created.

public
# moveTo( string $targetPath )

Move the uploaded file to a new location.

Move the uploaded file to a new location.

Use this method as an alternative to move_uploaded_file(). This method is guaranteed to work in both SAPI and non-SAPI environments. Implementations must determine which environment they are in, and use the appropriate method (move_uploaded_file(), rename(), or a stream operation) to perform the operation.

$targetPath may be an absolute path, or a relative path. If it is a relative path, resolution should be the same as used by PHP's rename() function.

The original file or stream MUST be removed on completion.

If this method is called more than once, any subsequent calls MUST raise an exception.

When used in an SAPI environment where $_FILES is populated, when writing files via moveTo(), is_uploaded_file() and move_uploaded_file() SHOULD be used to ensure permissions and upload status are verified correctly.

If you wish to move to a stream, use getStream(), as SAPI operations cannot guarantee writing to stream destinations.

Parameters

$targetPath
Path to which to move the uploaded file.

Throws

InvalidArgumentException
if the $path specified is invalid.
RuntimeException

on any error during the move operation, or on the second or subsequent call to the method.

See

http://php.net/is_uploaded_file
http://php.net/move_uploaded_file
public integer
# getError( )

Retrieve the error associated with the uploaded file.

Retrieve the error associated with the uploaded file.

The return value MUST be one of PHP's UPLOAD_ERR_XXX constants.

If the file was uploaded successfully, this method MUST return UPLOAD_ERR_OK.

Implementations SHOULD return the value stored in the "error" key of the file in the $_FILES array.

Returns

integer
One of PHP's UPLOAD_ERR_XXX constants.

See

http://php.net/manual/en/features.file-upload.errors.php
public string|null
# getClientFilename( )

Retrieve the filename sent by the client.

Retrieve the filename sent by the client.

Do not trust the value returned by this method. A client could send a malicious filename with the intention to corrupt or hack your application.

Implementations SHOULD return the value stored in the "name" key of the file in the $_FILES array.

Returns

string|null

The filename sent by the client or null if none was provided.

public string|null
# getClientMediaType( )

Retrieve the media type sent by the client.

Retrieve the media type sent by the client.

Do not trust the value returned by this method. A client could send a malicious media type with the intention to corrupt or hack your application.

Implementations SHOULD return the value stored in the "type" key of the file in the $_FILES array.

Returns

string|null

The media type sent by the client or null if none was provided.

public integer|null
# getSize( )

Retrieve the file size.

Retrieve the file size.

Implementations SHOULD return the value stored in the "size" key of the file in the $_FILES array if available, as PHP calculates this based on the actual size transmitted.

Returns

integer|null
The file size in bytes or null if unknown.

Properties summary

public string $file

The client-provided full path to the file

The client-provided full path to the file

Note

this is public to maintain BC with 3.1.0 and earlier.
#
protected string $name

The client-provided file name.

The client-provided file name.

#
protected string $type

The client-provided media type of the file.

The client-provided media type of the file.

#
protected integer $size

The size of the file in bytes.

The size of the file in bytes.

#
protected integer $error

A valid PHP UPLOAD_ERR_xxx code for the file upload.

A valid PHP UPLOAD_ERR_xxx code for the file upload.

# UPLOAD_ERR_OK
protected boolean $sapi

Indicates if the upload is from a SAPI environment.

Indicates if the upload is from a SAPI environment.

# false
protected Psr\Http\Message\StreamInterface $stream

An optional StreamInterface wrapping the file resource.

An optional StreamInterface wrapping the file resource.

#
protected boolean $moved

Indicates if the uploaded file has already been moved.

Indicates if the uploaded file has already been moved.

# false
API documentation generated by ApiGen