Commit b72600cc authored by Gábor Hojtsy's avatar Gábor Hojtsy

#172943 by drewish: fix file_save_upload() conformance to its API...

#172943 by drewish: fix file_save_upload() conformance to its API documentation by treating the 'dest' param as a directory. Also fixes #176876 so temporary files are properly stored in the temp directory.
parent 4e187261
......@@ -460,9 +460,6 @@ function file_space_used($uid = NULL) {
*
* @param $source
* A string specifying the name of the upload field to save.
* @param $dest
* A string containing the directory $source should be copied to. If this is
* not provided, the temporary directory will be used.
* @param $validators
* An optional, associative array of callback functions used to validate the
* file. The keys are function names and the values arrays of callback
......@@ -470,6 +467,9 @@ function file_space_used($uid = NULL) {
* functions should return an array of error messages, an empty array
* indicates that the file passed validation. The functions will be called in
* the order specified.
* @param $dest
* A string containing the directory $source should be copied to. If this is
* not provided or is not writable, the temporary directory will be used.
* @param $replace
* A boolean indicating whether an existing file of the same name in the
* destination directory should overwritten. A false value will generate a
......@@ -536,12 +536,14 @@ function file_save_upload($source, $validators = array(), $dest = FALSE, $replac
$file->filename .= '.txt';
}
// Create temporary name/path for newly uploaded files.
if (!$dest) {
$dest = file_destination(file_create_path($file->filename), FILE_EXISTS_RENAME);
// If the destination is not provided, or is not writable, then use the
// temporary directory.
if (empty($dest) || file_check_path($dest) === FALSE) {
$dest = file_directory_temp();
}
$file->source = $source;
$file->destination = $dest;
$file->destination = file_destination(file_create_path($dest .'/'. $file->filename), FILE_EXISTS_RENAME);
$file->filesize = $_FILES['files']['size'][$source];
// Call the validation functions.
......
......@@ -183,7 +183,7 @@ function upload_node_form_submit($form, &$form_state) {
);
// Save new file uploads.
if (($user->uid != 1 || user_access('upload files')) && ($file = file_save_upload('upload', $validators))) {
if (($user->uid != 1 || user_access('upload files')) && ($file = file_save_upload('upload', $validators, file_directory_path()))) {
$file->list = variable_get('upload_list_default', 1);
$file->description = $file->filename;
$_SESSION['upload_current_file'] = $file->fid;
......
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