This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -142,24 +142,26 @@ public function getStream()
142142 */
143143 public function moveTo ($ targetPath )
144144 {
145- if ($ this ->error !== UPLOAD_ERR_OK ) {
146- throw new RuntimeException ('Cannot retrieve stream due to upload error ' );
145+ if ($ this ->moved ) {
146+ throw new RuntimeException ('Cannot move file; already moved! ' );
147147 }
148148
149- if (! is_string ($ targetPath )) {
150- throw new InvalidArgumentException (
151- 'Invalid path provided for move operation; must be a string '
152- );
149+ if ($ this ->error !== UPLOAD_ERR_OK ) {
150+ throw new RuntimeException ('Cannot retrieve stream due to upload error ' );
153151 }
154152
155- if (empty ($ targetPath )) {
153+ if (! is_string ( $ targetPath ) || empty ($ targetPath )) {
156154 throw new InvalidArgumentException (
157155 'Invalid path provided for move operation; must be a non-empty string '
158156 );
159157 }
160158
161- if ($ this ->moved ) {
162- throw new RuntimeException ('Cannot move file; already moved! ' );
159+ $ targetDirectory = dirname ($ targetPath );
160+ if (! is_dir ($ targetDirectory ) || ! is_writable ($ targetDirectory )) {
161+ throw new RuntimeException (sprintf (
162+ 'The target directory `%s` does not exists or is not writable ' ,
163+ $ targetDirectory
164+ ));
163165 }
164166
165167 $ sapi = PHP_SAPI ;
You can’t perform that action at this time.
0 commit comments