I'm getting the error message
Notice: Undefined index: #field_name in file_managed_file_save_upload() ... line 630 file.module
and could not help myself nor find help on the web.
I defined an image field and tried to upload a default picture. This is being refused. Could be something with the upload directory. Any idea what the problem is?
Thanks in advance,
upunkt
The PHP code is the following:
/**
* Given a managed_file element, save any files that have been uploaded into it.
*
* @param $element
* The FAPI element whose values are being saved.
* @return
* The file object representing the file that was saved, or FALSE if no file
* was saved.
*/
function file_managed_file_save_upload($element) {
$upload_name = implode('_', $element['#parents']);
if (empty($_FILES['files']['name'][$upload_name])) {
return FALSE;
}
$destination = isset($element['#upload_location']) ? $element['#upload_location'] : NULL;
if (isset($destination) && !file_prepare_directory($destination, FILE_CREATE_DIRECTORY)) {
watchdog('file', 'The upload directory %directory for the file field !name 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' => $destination, '!name' => $element['#field_name']));
form_set_error($upload_name, t('The file could not be uploaded.'));
return FALSE;
}
if (!$file = file_save_upload($upload_name, $element['#upload_validators'], $destination)) {
watchdog('file', 'The file upload failed. %upload', array('%upload' => $upload_name));
form_set_error($upload_name, t('The file in the !name field was unable to be uploaded.', array('!name' => $element['#title'])));
return FALSE;
}
return $file;
}
Comments
Comment #1
upunkt CreditAttribution: upunkt commentedCould be solved by setting folder permissions of sites/default/files to owner "nobody" and read/write access. More information to be found here:
http://drupal.org/node/231865#comment-3917728
http://drupal.org/node/202483
Comment #2
rooby CreditAttribution: rooby commentedJust for reference, the error was triggered by the files directory not being writable however there is still an underlying bug in drupal core that is causing the undefined index error.
See #1903010: Notice: Undefined index: #field_name in file_managed_file_save_upload()
Comment #2.0
rooby CreditAttribution: rooby commentedAdded shown error message to Description
Comment #3
Shashwat Purav CreditAttribution: Shashwat Purav commentedHello,
I am getting same error in my site when I try to upload image in custom block module. I ported site from one server to another server. On previous server it was working fine but, now on current server I am getting error. I have checked directory permissions. I have given 755 to files inside default but no luck. Thanking you in anticipation.
Comment #4
Shashwat Purav CreditAttribution: Shashwat Purav commentedIt's working now. The problem was with httpd.conf file. I changed permissions in the file and restart apache and it started working.