@@ -53,18 +53,20 @@ class UploadedFile implements UploadedFileInterface
5353
5454 public function __construct ($ streamOrFile , $ size , $ errorStatus , $ clientFilename = null , $ clientMediaType = null )
5555 {
56- if (is_string ($ streamOrFile )) {
57- $ this ->file = $ streamOrFile ;
58- }
59- if (is_resource ($ streamOrFile )) {
60- $ this ->stream = new Stream ($ streamOrFile );
61- }
56+ if ($ errorStatus === UPLOAD_ERR_OK ) {
57+ if (is_string ($ streamOrFile )) {
58+ $ this ->file = $ streamOrFile ;
59+ }
60+ if (is_resource ($ streamOrFile )) {
61+ $ this ->stream = new Stream ($ streamOrFile );
62+ }
6263
63- if (! $ this ->file && ! $ this ->stream ) {
64- if (! $ streamOrFile instanceof StreamInterface) {
65- throw new InvalidArgumentException ('Invalid stream or file provided for UploadedFile ' );
64+ if (! $ this ->file && ! $ this ->stream ) {
65+ if (! $ streamOrFile instanceof StreamInterface) {
66+ throw new InvalidArgumentException ('Invalid stream or file provided for UploadedFile ' );
67+ }
68+ $ this ->stream = $ streamOrFile ;
6669 }
67- $ this ->stream = $ streamOrFile ;
6870 }
6971
7072 if (! is_int ($ size )) {
@@ -99,9 +101,14 @@ public function __construct($streamOrFile, $size, $errorStatus, $clientFilename
99101
100102 /**
101103 * {@inheritdoc}
104+ * @throws \RuntimeException if the upload was not successful.
102105 */
103106 public function getStream ()
104107 {
108+ if ($ this ->error !== UPLOAD_ERR_OK ) {
109+ throw new RuntimeException ('Cannot retrieve stream due to upload error ' );
110+ }
111+
105112 if ($ this ->moved ) {
106113 throw new RuntimeException ('Cannot retrieve stream after it has already been moved ' );
107114 }
@@ -120,12 +127,17 @@ public function getStream()
120127 * @see http://php.net/is_uploaded_file
121128 * @see http://php.net/move_uploaded_file
122129 * @param string $targetPath Path to which to move the uploaded file.
130+ * @throws \RuntimeException if the upload was not successful.
123131 * @throws \InvalidArgumentException if the $path specified is invalid.
124132 * @throws \RuntimeException on any error during the move operation, or on
125133 * the second or subsequent call to the method.
126134 */
127135 public function moveTo ($ targetPath )
128136 {
137+ if ($ this ->error !== UPLOAD_ERR_OK ) {
138+ throw new RuntimeException ('Cannot retrieve stream due to upload error ' );
139+ }
140+
129141 if (! is_string ($ targetPath )) {
130142 throw new InvalidArgumentException (
131143 'Invalid path provided for move operation; must be a string '
0 commit comments