17 use Psr\Http\Message\StreamInterface;
18 use Psr\Http\Message\UploadedFileInterface;
80 if (is_string($input)) {
84 if (is_resource($input)) {
85 $this->stream =
new Stream($input);
86 } elseif ($input instanceof StreamInterface) {
87 $this->stream = $input;
90 if (!$this->file && !$this->stream) {
91 throw new \InvalidArgumentException(
'The input given was not a valid stream or file.', 1436717301);
95 throw new \InvalidArgumentException(
'The size provided for an uploaded file must be an integer.', 1436717302);
99 if (!is_int($errorStatus) || 0 > $errorStatus || 8 < $errorStatus) {
100 throw new \InvalidArgumentException(
'Invalid error status for an uploaded file. See UPLOAD_ERR_* constant in PHP.', 1436717303);
102 $this->error = $errorStatus;
105 throw new \InvalidArgumentException(
'Invalid client filename provided for an uploaded file.', 1436717304);
110 throw new \InvalidArgumentException(
'Invalid client media type provided for an uploaded file.', 1436717305);
130 throw new \RuntimeException(
'Cannot retrieve stream as it was moved.', 1436717306);
133 if ($this->stream instanceof StreamInterface) {
137 $this->stream =
new Stream($this->file);
172 public function moveTo($targetPath)
174 if (!is_string($targetPath) || empty($targetPath)) {
175 throw new \InvalidArgumentException(
'Invalid path while moving an uploaded file.', 1436717307);
179 throw new \RuntimeException(
'Cannot move uploaded file, as it was already moved.', 1436717308);
183 $targetPath = GeneralUtility::getFileAbsFileName($targetPath);
184 if (empty($targetPath)) {
185 throw new \RuntimeException(
'Cannot move uploaded file, as it was already moved.', 1436717309);
188 if (!empty($this->file) && is_uploaded_file($this->file)) {
189 if (GeneralUtility::upload_copy_move($this->file, $targetPath .
PathUtility::basename($this->file)) ===
false) {
190 throw new \RuntimeException(
'An error occurred while moving uploaded file', 1436717310);
192 } elseif ($this->stream) {
193 $handle = fopen($targetPath,
'wb+');
194 if ($handle ===
false) {
195 throw new \RuntimeException(
'Unable to write to target path.', 1436717311);
198 $this->stream->rewind();
199 while (!$this->stream->eof()) {
200 fwrite($handle, $this->stream->read(4096));