summaryrefslogtreecommitdiff
path: root/includes/file.inc
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-12-22 00:18:42 -0800
committerwebchick <webchick@24967.no-reply.drupal.org>2011-12-22 00:18:42 -0800
commit880df4ed34d4489641f4ec49070e62918831e088 (patch)
treebb58d14747fd3970d2cc07e6d677cbea6db52c18 /includes/file.inc
parent7cf4dea7c6ed18a865c18d096d86b676753e2c37 (diff)
downloadbrdo-880df4ed34d4489641f4ec49070e62918831e088.tar.gz
brdo-880df4ed34d4489641f4ec49070e62918831e088.tar.bz2
Issue #1240256 by lyricnz, Akaoni, jenspeter: Fixed file_unmanaged_copy() Fails with Drupal 7.7+ and safe_mode() or open_basedir().
Diffstat (limited to 'includes/file.inc')
-rw-r--r--includes/file.inc12
1 files changed, 10 insertions, 2 deletions
diff --git a/includes/file.inc b/includes/file.inc
index 40e8349a0..6ee1b40b9 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -828,6 +828,10 @@ function file_valid_uri($uri) {
* is reported.
* - If file already exists in $destination either the call will error out,
* replace the file or rename the file based on the $replace parameter.
+ * - Provides a fallback using realpaths if the move fails using stream
+ * wrappers. This can occur because PHP's copy() function does not properly
+ * support streams if safe_mode or open_basedir are enabled. See
+ * https://bugs.php.net/bug.php?id=60456
*
* @param $source
* A string specifying the filepath or URI of the source file.
@@ -907,8 +911,12 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
file_ensure_htaccess();
// Perform the copy operation.
if (!@copy($source, $destination)) {
- watchdog('file', 'The specified file %file could not be copied to %destination.', array('%file' => $source, '%destination' => $destination), WATCHDOG_ERROR);
- return FALSE;
+ // If the copy failed and realpaths exist, retry the operation using them
+ // instead.
+ if ($real_source === FALSE || $real_destination === FALSE || !@copy($real_source, $real_destination)) {
+ watchdog('file', 'The specified file %file could not be copied to %destination.', array('%file' => $source, '%destination' => $destination), WATCHDOG_ERROR);
+ return FALSE;
+ }
}
// Set the permissions on the new file.