From 10dea948f38a684336fa965176529917ff7fe533 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Sun, 28 Apr 2013 18:32:44 +0300 Subject: [PATCH] [Filesystem] copy() is not working when open_basedir is set More details: https://bugs.php.net/bug.php?id=64634 --- src/Symfony/Component/Filesystem/Filesystem.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 778bd236f3..c3050423c1 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -35,6 +35,10 @@ class Filesystem */ public function copy($originFile, $targetFile, $override = false) { + if (!is_file($originFile)) { + throw new IOException(sprintf('Failed to copy %s because file not exists', $originFile)); + } + $this->mkdir(dirname($targetFile)); if (!$override && is_file($targetFile)) { @@ -44,7 +48,15 @@ class Filesystem } if ($doCopy) { - if (true !== @copy($originFile, $targetFile)) { + // https://bugs.php.net/bug.php?id=64634 + $source = fopen($originFile, 'r'); + $target = fopen($targetFile, 'w+'); + stream_copy_to_stream($source, $target); + fclose($source); + fclose($target); + unset($source, $target); + + if (!is_file($targetFile)) { throw new IOException(sprintf('Failed to copy %s to %s', $originFile, $targetFile)); } }