summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--filefield_widget.inc14
1 files changed, 8 insertions, 6 deletions
diff --git a/filefield_widget.inc b/filefield_widget.inc
index 9c1b744..e3b744f 100644
--- a/filefield_widget.inc
+++ b/filefield_widget.inc
@@ -110,14 +110,16 @@ function _filefield_widget_settings_max_filesize_per_node_validate($element, &$f
*
* @param $field
* A CCK field array.
+ * @param $account
+ * The user account object to calculate the file path for.
* @return
* The files directory path, with any tokens replaced.
*/
-function filefield_widget_file_path($field_instance) {
- $dest = $field_instance['widget']['file_path'];
+function filefield_widget_file_path($field, $account = NULL) {
+ $account = isset($account) ? $account : $GLOBALS['user'];
+ $dest = $field['widget']['file_path'];
if (module_exists('token')) {
- global $user;
- $dest = token_replace($dest, 'user', $user);
+ $dest = token_replace($dest, 'user', $account);
}
return file_directory_path() .'/'. $dest;
@@ -134,13 +136,13 @@ function filefield_widget_file_path($field_instance) {
*/
function filefield_save_upload($element) {
$upload_name = $element['#field_name'] .'_'. $element['#delta'];
- $field_instance = content_fields($element['#field_name'], $element['#type_name']);
+ $field = content_fields($element['#field_name'], $element['#type_name']);
if (empty($_FILES['files']['name'][$upload_name])) {
return 0;
}
- $dest = filefield_widget_file_path($field_instance);
+ $dest = filefield_widget_file_path($field);
if (!field_file_check_directory($dest, FILE_CREATE_DIRECTORY)) {
watchdog('filefield', 'The upload directory %directory for the file field %field (content type %type) could not be created or is not accessible. A newly uploaded file could not be saved in this directory as a consequence, and the upload was canceled.', array('%directory' => $dest, '%field' => $element['#field_name'], '%type' => $element['#type_name']));
form_set_error($upload_name, t('The file could not be uploaded.'));