From b2730e86d588bcf7fd0f036571014b75d1bc992f Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Wed, 19 Aug 2009 08:38:09 +0000 Subject: #552066 by quicksketch and pwolanin: Fix bug with file_save_upload() and trailing slashes (with tests). --- includes/file.inc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'includes') diff --git a/includes/file.inc b/includes/file.inc index c0ce7c594..c0e68f52e 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -1067,7 +1067,7 @@ function file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT) { * the status and use file_save() to save the changes. * * @param $source - * A string specifying the filepath or URI of the upload field to save. + * A string specifying the filepath or URI of the uploaded file to save. * @param $validators * An optional, associative array of callback functions used to validate the * file. See file_validate() for a full discussion of the array format. @@ -1163,6 +1163,10 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, } $file->source = $source; + // A URI may already have a trailing slash or look like "public://". + if (substr($destination, -1) != '/') { + $destination .= '/'; + } $file->destination = file_destination($destination . $file->filename, $replace); // If file_destination() returns FALSE then $replace == FILE_EXISTS_ERROR and // there's an existing file so we need to bail. -- cgit v1.2.3