Permalink
Browse files

[Filesystem] copy() is not working when open_basedir is set

  • Loading branch information...
stloyd committed Apr 28, 2013
1 parent ed1e991 commit c8f0ee4495d39b73811a4f5498a2518c68107a1f
Showing with 13 additions and 1 deletion.
  1. +13 −1 Filesystem.php
View
@@ -35,6 +35,10 @@ class Filesystem
*/
public function copy($originFile, $targetFile, $override = false)
{
+ if (!is_file($originFile)) {

This comment has been minimized.

Show comment Hide comment
@kachkaev

kachkaev May 3, 2013

Adding this check makes it no longer possible to copy remote files. E. g.
$this->filesystem->copy('http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png', '/path/to/local/file.png', true);
now throws an exception.

@kachkaev

kachkaev May 3, 2013

Adding this check makes it no longer possible to copy remote files. E. g.
$this->filesystem->copy('http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png', '/path/to/local/file.png', true);
now throws an exception.

This comment has been minimized.

Show comment Hide comment
@fabpot

fabpot May 3, 2013

Member

Can you create a ticket so that this is not lost?

@fabpot

fabpot May 3, 2013

Member

Can you create a ticket so that this is not lost?

This comment has been minimized.

Show comment Hide comment
+ 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 @@ public function copy($originFile, $targetFile, $override = false)
}
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));
}
}

0 comments on commit c8f0ee4

Please sign in to comment.