Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

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

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.

@fabpot Owner
fabpot added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to 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));
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.