summaryrefslogtreecommitdiff
path: root/includes/file.inc
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-08-30 00:35:37 -0700
committerwebchick <webchick@24967.no-reply.drupal.org>2011-08-30 00:35:37 -0700
commit960ad9cf50fcb4eb5ea92be9345614c81e100e49 (patch)
tree6824dc6426e60f5a54fa1cd4642df741e00cc0e1 /includes/file.inc
parent0e591faf2ad645715dad6cceabb8fcf9c0c35c87 (diff)
downloadbrdo-960ad9cf50fcb4eb5ea92be9345614c81e100e49.tar.gz
brdo-960ad9cf50fcb4eb5ea92be9345614c81e100e49.tar.bz2
Issue #1002048 by Akaoni, Boobaa, joosts, sfyn, bfroehle: Fixed Work around move_uploaded_file() issues with safe_mode() and open_basedir().
Diffstat (limited to 'includes/file.inc')
-rw-r--r--includes/file.inc38
1 files changed, 37 insertions, 1 deletions
diff --git a/includes/file.inc b/includes/file.inc
index e0da21660..4fb56e8a4 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -1538,7 +1538,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE,
// directory. This overcomes open_basedir restrictions for future file
// operations.
$file->uri = $file->destination;
- if (!move_uploaded_file($_FILES['files']['tmp_name'][$source], $file->uri)) {
+ if (!drupal_move_uploaded_file($_FILES['files']['tmp_name'][$source], $file->uri)) {
form_set_error($source, t('File upload error. Could not move uploaded file.'));
watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->uri));
return FALSE;
@@ -1565,6 +1565,42 @@ function file_save_upload($source, $validators = array(), $destination = FALSE,
return FALSE;
}
+/**
+ * Moves an uploaded file to a new location.
+ *
+ * PHP's move_uploaded_file() does not properly support streams if safe_mode
+ * or open_basedir are enabled, so this function fills that gap.
+ *
+ * Compatibility: normal paths and stream wrappers.
+ * @see http://drupal.org/node/515192
+ *
+ * @param $filename
+ * The filename of the uploaded file.
+ * @param $uri
+ * A string containing the destination URI of the file.
+ *
+ * @return
+ * TRUE on success, or FALSE on failure.
+ *
+ * @see move_uploaded_file()
+ * @ingroup php_wrappers
+ */
+function drupal_move_uploaded_file($filename, $uri) {
+ $result = @move_uploaded_file($filename, $uri);
+ // PHP's move_uploaded_file() does not properly support streams if safe_mode
+ // or open_basedir are enabled so if the move failed, try finding a real path
+ // and retry the move operation.
+ if (!$result) {
+ if ($realpath = drupal_realpath($uri)) {
+ $result = move_uploaded_file($filename, $realpath);
+ }
+ else {
+ $result = move_uploaded_file($filename, $uri);
+ }
+ }
+
+ return $result;
+}
/**
* Check that a file meets the criteria specified by the validators.