4use InvalidArgumentException;
20 UPLOAD_ERR_NO_TMP_DIR,
21 UPLOAD_ERR_CANT_WRITE,
92 if (is_string($streamOrFile)) {
93 $this->file = $streamOrFile;
94 } elseif (is_resource($streamOrFile)) {
95 $this->stream =
new Stream($streamOrFile);
97 $this->stream = $streamOrFile;
99 throw new InvalidArgumentException(
100 'Invalid stream or file provided for UploadedFile'
111 if (
false === is_int(
$error)) {
112 throw new InvalidArgumentException(
113 'Upload file error status must be an integer'
118 throw new InvalidArgumentException(
119 'Invalid error status for UploadedFile'
132 if (
false === is_int(
$size)) {
133 throw new InvalidArgumentException(
134 'Upload file size must be an integer'
147 return in_array(gettype($param), [
'string',
'NULL']);
156 return is_string($param) &&
false === empty($param);
166 throw new InvalidArgumentException(
167 'Upload file client filename must be a string or null'
181 throw new InvalidArgumentException(
182 'Upload file client media type must be a string or null'
196 return $this->
error === UPLOAD_ERR_OK;
212 if (
false === $this->
isOk()) {
213 throw new RuntimeException(
'Cannot retrieve stream due to upload error');
217 throw new RuntimeException(
'Cannot retrieve stream after it has already been moved');
252 throw new InvalidArgumentException(
253 'Invalid path provided for move operation; must be a non-empty string'
258 $this->moved = php_sapi_name() ==
'cli'
259 ? rename($this->file, $targetPath)
260 : move_uploaded_file($this->file, $targetPath);
270 if (
false === $this->moved) {
271 throw new RuntimeException(
272 sprintf(
'Uploaded file could not be moved to %s', $targetPath)
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Lazily reads or writes to a file that is opened only after an IO operation take place on the stream.
__construct( $streamOrFile, $size, $errorStatus, $clientFilename=null, $clientMediaType=null)
setStreamOrFile($streamOrFile)
Depending on the value set file or stream variable.
setClientFilename($clientFilename)
isOk()
Return true if there is no upload error.
getStream()
{Retrieve a stream representing the uploaded file.This method MUST return a StreamInterface instance,...
moveTo($targetPath)
{Move the uploaded file to a new location.Use this method as an alternative to move_uploaded_file()....
getClientFilename()
{Retrieve the filename sent by the client.Do not trust the value returned by this method....
setClientMediaType($clientMediaType)
getError()
{Retrieve the error associated with the uploaded file.The return value MUST be one of PHP's UPLOAD_ER...
getSize()
{Retrieve the file size.Implementations SHOULD return the value stored in the "size" key of the file ...
getClientMediaType()
{Retrieve the media type sent by the client.Do not trust the value returned by this method....
error($a_errmsg)
set error message @access public
Value object representing a file uploaded through an HTTP request.
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.