Commit 65a31d68 authored by catch's avatar catch
Browse files

Issue #1240256 by lyricnz, Akaoni: Fixed file_unmanaged_copy() Fails with...

Issue #1240256 by lyricnz, Akaoni: Fixed file_unmanaged_copy() Fails with Drupal 7.7+ and safe_mode() or open_basedir().
parent d8ca0259
......@@ -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
* @param $source
* A string specifying the filepath or URI of the source file.
......@@ -907,9 +911,13 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
// Perform the copy operation.
if (!@copy($source, $destination)) {
// 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.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment