Skip to content

Commit da48c21

Browse files
[Filesystem] Fix usages of error_get_last()
1 parent 9f01f9b commit da48c21

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

File/File.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ public function move($directory, $name = null)
9393
{
9494
$target = $this->getTargetFile($directory, $name);
9595

96-
if (!@rename($this->getPathname(), $target)) {
97-
$error = error_get_last();
98-
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message'])));
96+
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
97+
$renamed = rename($this->getPathname(), $target);
98+
restore_error_handler();
99+
if (!$renamed) {
100+
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error)));
99101
}
100102

101103
@chmod($target, 0666 & ~umask());

File/UploadedFile.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ public function move($directory, $name = null)
192192

193193
$target = $this->getTargetFile($directory, $name);
194194

195-
if (!@move_uploaded_file($this->getPathname(), $target)) {
196-
$error = error_get_last();
197-
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message'])));
195+
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
196+
$moved = move_uploaded_file($this->getPathname(), $target);
197+
restore_error_handler();
198+
if (!$moved) {
199+
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error)));
198200
}
199201

200202
@chmod($target, 0666 & ~umask());

0 commit comments

Comments
 (0)