34 $fileMimeType = (string)$request->getHeader(
'Content-Type');
35 if (!preg_match(
'~\w+/[-+.\w]+~', $fileMimeType))
40 $contentLength = $request->getHeader(
'Content-Length');
41 if ($contentLength ===
null)
46 $contentLength = (int)$contentLength;
47 $filename = static::normalizeFilename((
string)$request->getHeader(
'X-Upload-Content-Name'));
53 if (!static::isValidFilename($filename))
58 $contentRangeResult = static::getContentRange($request);
59 if (!$contentRangeResult->isSuccess())
61 return $result->addErrors($contentRangeResult->getErrors());
64 $file = static::getFileFromHttpInput();
65 $contentRange = $contentRangeResult->getData();
66 $rangeChunkSize = empty($contentRange) ? 0 : ($contentRange[
'endRange'] - $contentRange[
'startRange'] + 1);
68 if ($rangeChunkSize && $contentLength !== $rangeChunkSize)
73 'rangeChunkSize' => $rangeChunkSize,
74 'contentLength' => $contentLength,
80 if ($chunk->getSize() !== $contentLength)
85 'chunkSize' => $chunk->getSize(),
86 'contentLength' => $contentLength,
91 $chunk->setName($filename);
92 $chunk->setType($fileMimeType);
94 if (!empty($contentRange))
96 $chunk->setStartRange($contentRange[
'startRange']);
97 $chunk->setEndRange($contentRange[
'endRange']);
98 $chunk->setFileSize($contentRange[
'fileSize']);
101 $result->setData([
'chunk' => $chunk]);
285 if (in_array(mb_strtolower($this->
getName()), $config->getIgnoredFileNames()))
290 if ($config->getMaxFileSize() !==
null && $this->getFileSize() > $config->getMaxFileSize())
292 return $result->addError(
296 'maxFileSize' => \CFile::formatSize($config->getMaxFileSize()),
297 'maxFileSizeInBytes' => $config->getMaxFileSize(),
303 if ($this->
getFileSize() < $config->getMinFileSize())
305 return $result->addError(
309 'minFileSize' => \CFile::formatSize($config->getMinFileSize()),
310 'minFileSizeInBytes' => $config->getMinFileSize(),
316 if (!$this->validateFileType($config->getAcceptedFileTypes()))
325 $image =
new File\Image($this->
getFile()->getPhysicalPath());
326 $imageInfo = $image->getInfo(
false);
329 if ($config->getIgnoreUnknownImageTypes())
341 $width = $imageInfo->getWidth();
342 $height = $imageInfo->getHeight();
345 $exifData = $image->getExifData();
346 if (isset($exifData[
'Orientation']) && $exifData[
'Orientation'] >= 5 && $exifData[
'Orientation'] <= 8)
352 if (!$config->shouldTreatOversizeImageAsFile())
355 $imageData->setWidth(
$width);
356 $imageData->setHeight(
$height);
358 $validationResult = $config->validateImage($imageData);
359 if (!$validationResult->isSuccess())
361 return $result->addErrors($validationResult->getErrors());