ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
GuzzleHttp\Psr7\UploadedFile Class Reference
+ Inheritance diagram for GuzzleHttp\Psr7\UploadedFile:
+ Collaboration diagram for GuzzleHttp\Psr7\UploadedFile:

Public Member Functions

 __construct ( $streamOrFile, $size, $errorStatus, $clientFilename=null, $clientMediaType=null)
 
 isMoved ()
 
 getStream ()
 {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
StreamInterface Stream representation of the uploaded file.
Exceptions

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

 
 moveTo ($targetPath)
 {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.
See also
http://php.net/is_uploaded_file
http://php.net/move_uploaded_file
Parameters
string$targetPathPath to which to move the uploaded file.
Exceptions

InvalidArgumentException if the $targetPath specified is invalid.

Exceptions

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

 
 getSize ()
 {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
int|null The file size in bytes or null if unknown.
} More...
 
 getError ()
 {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.
See also
http://php.net/manual/en/features.file-upload.errors.php
Returns
int One of PHP's UPLOAD_ERR_XXX constants.
} More...
 
 getClientFilename ()
 {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.
} More...
 
 getClientMediaType ()
 {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.
} More...
 
 getStream ()
 Retrieve a stream representing the uploaded file. More...
 
 moveTo ($targetPath)
 Move the uploaded file to a new location. More...
 
 getSize ()
 Retrieve the file size. More...
 
 getError ()
 Retrieve the error associated with the uploaded file. More...
 
 getClientFilename ()
 Retrieve the filename sent by the client. More...
 
 getClientMediaType ()
 Retrieve the media type sent by the client. More...
 

Private Member Functions

 setStreamOrFile ($streamOrFile)
 Depending on the value set file or stream variable. More...
 
 setError ($error)
 
 setSize ($size)
 
 isStringOrNull ($param)
 
 isStringNotEmpty ($param)
 
 setClientFilename ($clientFilename)
 
 setClientMediaType ($clientMediaType)
 
 isOk ()
 Return true if there is no upload error. More...
 
 validateActive ()
 

Private Attributes

 $clientFilename
 
 $clientMediaType
 
 $error
 
 $file
 
 $moved = false
 
 $size
 
 $stream
 

Static Private Attributes

static $errors
 

Detailed Description

Definition at line 9 of file UploadedFile.php.

Constructor & Destructor Documentation

◆ __construct()

GuzzleHttp\Psr7\UploadedFile::__construct (   $streamOrFile,
  $size,
  $errorStatus,
  $clientFilename = null,
  $clientMediaType = null 
)
Parameters
StreamInterface | string | resource$streamOrFile
int$size
int$errorStatus
string | null$clientFilename
string | null$clientMediaType

Definition at line 67 of file UploadedFile.php.

73 {
74 $this->setError($errorStatus);
75 $this->setSize($size);
78
79 if ($this->isOk()) {
80 $this->setStreamOrFile($streamOrFile);
81 }
82 }
setStreamOrFile($streamOrFile)
Depending on the value set file or stream variable.
setClientFilename($clientFilename)
isOk()
Return true if there is no upload error.
setClientMediaType($clientMediaType)

References GuzzleHttp\Psr7\UploadedFile\$clientFilename, GuzzleHttp\Psr7\UploadedFile\$clientMediaType, GuzzleHttp\Psr7\UploadedFile\$size, GuzzleHttp\Psr7\UploadedFile\isOk(), GuzzleHttp\Psr7\UploadedFile\setClientFilename(), GuzzleHttp\Psr7\UploadedFile\setClientMediaType(), GuzzleHttp\Psr7\UploadedFile\setError(), GuzzleHttp\Psr7\UploadedFile\setSize(), and GuzzleHttp\Psr7\UploadedFile\setStreamOrFile().

+ Here is the call graph for this function:

Member Function Documentation

◆ getClientFilename()

GuzzleHttp\Psr7\UploadedFile::getClientFilename ( )

{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.
}

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

Implements Psr\Http\Message\UploadedFileInterface.

Definition at line 304 of file UploadedFile.php.

305 {
307 }

References GuzzleHttp\Psr7\UploadedFile\$clientFilename.

◆ getClientMediaType()

GuzzleHttp\Psr7\UploadedFile::getClientMediaType ( )

{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.
}

Implements Psr\Http\Message\UploadedFileInterface.

Definition at line 312 of file UploadedFile.php.

313 {
315 }

References GuzzleHttp\Psr7\UploadedFile\$clientMediaType.

◆ getError()

GuzzleHttp\Psr7\UploadedFile::getError ( )

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

See also
http://php.net/manual/en/features.file-upload.errors.php
Returns
int One of PHP's UPLOAD_ERR_XXX constants.
}

See also
http://php.net/manual/en/features.file-upload.errors.php
Returns
int One of PHP's UPLOAD_ERR_XXX constants.

Implements Psr\Http\Message\UploadedFileInterface.

Definition at line 293 of file UploadedFile.php.

294 {
295 return $this->error;
296 }

References GuzzleHttp\Psr7\UploadedFile\$error.

◆ getSize()

GuzzleHttp\Psr7\UploadedFile::getSize ( )

{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
int|null The file size in bytes or null if unknown.
}

Returns
int|null The file size in bytes or null if unknown.

Implements Psr\Http\Message\UploadedFileInterface.

Definition at line 282 of file UploadedFile.php.

283 {
284 return $this->size;
285 }

References GuzzleHttp\Psr7\UploadedFile\$size.

◆ getStream()

GuzzleHttp\Psr7\UploadedFile::getStream ( )

{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
StreamInterface Stream representation of the uploaded file.
Exceptions

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

Exceptions
RuntimeExceptionif the upload was not successful.

Implements Psr\Http\Message\UploadedFileInterface.

Definition at line 225 of file UploadedFile.php.

226 {
227 $this->validateActive();
228
229 if ($this->stream instanceof StreamInterface) {
230 return $this->stream;
231 }
232
233 return new LazyOpenStream($this->file, 'r+');
234 }

References GuzzleHttp\Psr7\UploadedFile\$stream, and GuzzleHttp\Psr7\UploadedFile\validateActive().

Referenced by GuzzleHttp\Psr7\UploadedFile\moveTo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isMoved()

GuzzleHttp\Psr7\UploadedFile::isMoved ( )
Returns
boolean

Definition at line 202 of file UploadedFile.php.

203 {
204 return $this->moved;
205 }

References GuzzleHttp\Psr7\UploadedFile\$moved.

Referenced by GuzzleHttp\Psr7\UploadedFile\validateActive().

+ Here is the caller graph for this function:

◆ isOk()

GuzzleHttp\Psr7\UploadedFile::isOk ( )
private

Return true if there is no upload error.

Returns
boolean

Definition at line 194 of file UploadedFile.php.

195 {
196 return $this->error === UPLOAD_ERR_OK;
197 }
error($a_errmsg)
set error message @access public

References error().

Referenced by GuzzleHttp\Psr7\UploadedFile\__construct(), and GuzzleHttp\Psr7\UploadedFile\validateActive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isStringNotEmpty()

GuzzleHttp\Psr7\UploadedFile::isStringNotEmpty (   $param)
private
Parameters
mixed$param
Returns
boolean

Definition at line 154 of file UploadedFile.php.

155 {
156 return is_string($param) && false === empty($param);
157 }

Referenced by GuzzleHttp\Psr7\UploadedFile\moveTo().

+ Here is the caller graph for this function:

◆ isStringOrNull()

GuzzleHttp\Psr7\UploadedFile::isStringOrNull (   $param)
private
Parameters
mixed$param
Returns
boolean

Definition at line 145 of file UploadedFile.php.

146 {
147 return in_array(gettype($param), ['string', 'NULL']);
148 }

Referenced by GuzzleHttp\Psr7\UploadedFile\setClientFilename(), and GuzzleHttp\Psr7\UploadedFile\setClientMediaType().

+ Here is the caller graph for this function:

◆ moveTo()

GuzzleHttp\Psr7\UploadedFile::moveTo (   $targetPath)

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

See also
http://php.net/is_uploaded_file
http://php.net/move_uploaded_file
Parameters
string$targetPathPath to which to move the uploaded file.
Exceptions

InvalidArgumentException if the $targetPath specified is invalid.

Exceptions

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

See also
http://php.net/is_uploaded_file
http://php.net/move_uploaded_file
Parameters
string$targetPathPath to which to move the uploaded file.
Exceptions
RuntimeExceptionif the upload was not successful.
InvalidArgumentExceptionif the $path specified is invalid.
RuntimeExceptionon any error during the move operation, or on the second or subsequent call to the method.

Implements Psr\Http\Message\UploadedFileInterface.

Definition at line 247 of file UploadedFile.php.

248 {
249 $this->validateActive();
250
251 if (false === $this->isStringNotEmpty($targetPath)) {
252 throw new InvalidArgumentException(
253 'Invalid path provided for move operation; must be a non-empty string'
254 );
255 }
256
257 if ($this->file) {
258 $this->moved = php_sapi_name() == 'cli'
259 ? rename($this->file, $targetPath)
260 : move_uploaded_file($this->file, $targetPath);
261 } else {
263 $this->getStream(),
264 new LazyOpenStream($targetPath, 'w')
265 );
266
267 $this->moved = true;
268 }
269
270 if (false === $this->moved) {
271 throw new RuntimeException(
272 sprintf('Uploaded file could not be moved to %s', $targetPath)
273 );
274 }
275 }
getStream()
{Retrieve a stream representing the uploaded file.This method MUST return a StreamInterface instance,...
copy_to_stream(StreamInterface $source, StreamInterface $dest, $maxLen=-1)
Copy the contents of a stream into another stream until the given number of bytes have been read.
Definition: functions.php:369

References GuzzleHttp\Psr7\copy_to_stream(), GuzzleHttp\Psr7\UploadedFile\getStream(), GuzzleHttp\Psr7\UploadedFile\isStringNotEmpty(), and GuzzleHttp\Psr7\UploadedFile\validateActive().

+ Here is the call graph for this function:

◆ setClientFilename()

GuzzleHttp\Psr7\UploadedFile::setClientFilename (   $clientFilename)
private
Parameters
string | null$clientFilename
Exceptions
InvalidArgumentException

Definition at line 163 of file UploadedFile.php.

164 {
165 if (false === $this->isStringOrNull($clientFilename)) {
166 throw new InvalidArgumentException(
167 'Upload file client filename must be a string or null'
168 );
169 }
170
171 $this->clientFilename = $clientFilename;
172 }

References GuzzleHttp\Psr7\UploadedFile\$clientFilename, and GuzzleHttp\Psr7\UploadedFile\isStringOrNull().

Referenced by GuzzleHttp\Psr7\UploadedFile\__construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setClientMediaType()

GuzzleHttp\Psr7\UploadedFile::setClientMediaType (   $clientMediaType)
private
Parameters
string | null$clientMediaType
Exceptions
InvalidArgumentException

Definition at line 178 of file UploadedFile.php.

179 {
180 if (false === $this->isStringOrNull($clientMediaType)) {
181 throw new InvalidArgumentException(
182 'Upload file client media type must be a string or null'
183 );
184 }
185
186 $this->clientMediaType = $clientMediaType;
187 }

References GuzzleHttp\Psr7\UploadedFile\$clientMediaType, and GuzzleHttp\Psr7\UploadedFile\isStringOrNull().

Referenced by GuzzleHttp\Psr7\UploadedFile\__construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setError()

GuzzleHttp\Psr7\UploadedFile::setError (   $error)
private
Parameters
int$error
Exceptions
InvalidArgumentException

Definition at line 109 of file UploadedFile.php.

110 {
111 if (false === is_int($error)) {
112 throw new InvalidArgumentException(
113 'Upload file error status must be an integer'
114 );
115 }
116
117 if (false === in_array($error, UploadedFile::$errors)) {
118 throw new InvalidArgumentException(
119 'Invalid error status for UploadedFile'
120 );
121 }
122
123 $this->error = $error;
124 }

References GuzzleHttp\Psr7\UploadedFile\$error, GuzzleHttp\Psr7\UploadedFile\$errors, and error().

Referenced by GuzzleHttp\Psr7\UploadedFile\__construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSize()

GuzzleHttp\Psr7\UploadedFile::setSize (   $size)
private
Parameters
int$size
Exceptions
InvalidArgumentException

Definition at line 130 of file UploadedFile.php.

131 {
132 if (false === is_int($size)) {
133 throw new InvalidArgumentException(
134 'Upload file size must be an integer'
135 );
136 }
137
138 $this->size = $size;
139 }
font size
Definition: langcheck.php:162

References GuzzleHttp\Psr7\UploadedFile\$size, and size.

Referenced by GuzzleHttp\Psr7\UploadedFile\__construct().

+ Here is the caller graph for this function:

◆ setStreamOrFile()

GuzzleHttp\Psr7\UploadedFile::setStreamOrFile (   $streamOrFile)
private

Depending on the value set file or stream variable.

Parameters
mixed$streamOrFile
Exceptions
InvalidArgumentException

Definition at line 90 of file UploadedFile.php.

91 {
92 if (is_string($streamOrFile)) {
93 $this->file = $streamOrFile;
94 } elseif (is_resource($streamOrFile)) {
95 $this->stream = new Stream($streamOrFile);
96 } elseif ($streamOrFile instanceof StreamInterface) {
97 $this->stream = $streamOrFile;
98 } else {
99 throw new InvalidArgumentException(
100 'Invalid stream or file provided for UploadedFile'
101 );
102 }
103 }

Referenced by GuzzleHttp\Psr7\UploadedFile\__construct().

+ Here is the caller graph for this function:

◆ validateActive()

GuzzleHttp\Psr7\UploadedFile::validateActive ( )
private
Exceptions
RuntimeExceptionif is moved or not ok

Definition at line 210 of file UploadedFile.php.

211 {
212 if (false === $this->isOk()) {
213 throw new RuntimeException('Cannot retrieve stream due to upload error');
214 }
215
216 if ($this->isMoved()) {
217 throw new RuntimeException('Cannot retrieve stream after it has already been moved');
218 }
219 }

References GuzzleHttp\Psr7\UploadedFile\isMoved(), and GuzzleHttp\Psr7\UploadedFile\isOk().

Referenced by GuzzleHttp\Psr7\UploadedFile\getStream(), and GuzzleHttp\Psr7\UploadedFile\moveTo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $clientFilename

GuzzleHttp\Psr7\UploadedFile::$clientFilename
private

◆ $clientMediaType

GuzzleHttp\Psr7\UploadedFile::$clientMediaType
private

◆ $error

GuzzleHttp\Psr7\UploadedFile::$error
private

◆ $errors

GuzzleHttp\Psr7\UploadedFile::$errors
staticprivate
Initial value:
= [
UPLOAD_ERR_OK,
UPLOAD_ERR_INI_SIZE,
UPLOAD_ERR_FORM_SIZE,
UPLOAD_ERR_PARTIAL,
UPLOAD_ERR_NO_FILE,
UPLOAD_ERR_NO_TMP_DIR,
UPLOAD_ERR_CANT_WRITE,
UPLOAD_ERR_EXTENSION,
]

Definition at line 14 of file UploadedFile.php.

Referenced by GuzzleHttp\Psr7\UploadedFile\setError().

◆ $file

GuzzleHttp\Psr7\UploadedFile::$file
private

Definition at line 43 of file UploadedFile.php.

◆ $moved

GuzzleHttp\Psr7\UploadedFile::$moved = false
private

Definition at line 48 of file UploadedFile.php.

Referenced by GuzzleHttp\Psr7\UploadedFile\isMoved().

◆ $size

GuzzleHttp\Psr7\UploadedFile::$size
private

◆ $stream

GuzzleHttp\Psr7\UploadedFile::$stream
private

Definition at line 58 of file UploadedFile.php.

Referenced by GuzzleHttp\Psr7\UploadedFile\getStream().


The documentation for this class was generated from the following file: