ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
} 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
} 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...
 

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.

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().

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.
isOk()
Return true if there is no upload error.
setClientMediaType($clientMediaType)
setClientFilename($clientFilename)
+ 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.

References GuzzleHttp\Psr7\UploadedFile\$clientFilename.

305  {
306  return $this->clientFilename;
307  }

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

References GuzzleHttp\Psr7\UploadedFile\$clientMediaType.

313  {
314  return $this->clientMediaType;
315  }

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

References GuzzleHttp\Psr7\UploadedFile\$error.

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

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

References GuzzleHttp\Psr7\UploadedFile\$size.

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

◆ 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
}

Exceptions
RuntimeExceptionif the upload was not successful.

Implements Psr\Http\Message\UploadedFileInterface.

Definition at line 225 of file UploadedFile.php.

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

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

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  }
Reload workbook from saved file
+ 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.

References GuzzleHttp\Psr7\UploadedFile\$moved.

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

203  {
204  return $this->moved;
205  }
+ 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.

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

195  {
196  return $this->error === UPLOAD_ERR_OK;
197  }
+ 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.

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

155  {
156  return is_string($param) && false === empty($param);
157  }
+ 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.

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

146  {
147  return in_array(gettype($param), ['string', 'NULL']);
148  }
+ 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
}

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.

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

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  }
Reload workbook from saved file
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
+ 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.

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

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

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

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

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

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

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

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

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

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

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

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  }
Set page orientation and size
Definition: 04printing.php:77
+ 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.

References file.

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

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  }
Reload workbook from saved file
+ 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.

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

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

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  }
isOk()
Return true if there is no upload error.
+ 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: