IMCE and FileField Sources, an update
Upon Marcelo's request I post my adjusted version of the filefield_sources/sources/imce.inc file. The following code replaces the function filefield_source_imce_value
function filefield_source_imce_value($element, &$item) {
global $base_path;
if (isset($item['filefield_imce']['file_path']) && $item['filefield_imce']['file_path'] != '') {
$field = field_info_field($element['#field_name']);
$scheme = $field['settings']['uri_scheme'];
$wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
$file_directory_prefix = $wrapper->getDirectoryPath();
$searchsrc = '/^(.*)' . preg_quote('/' . $file_directory_prefix . '/', '/') . '/';
if ($scheme == 'private') {
$searchsrc = '/^(.*)' . preg_quote('/system/files' . '/', '/') . '/';
}
$uri = preg_replace($searchsrc, $scheme . '://', $item['filefield_imce']['file_path']);
// Resolve the file path to an FID.
$fid = db_select('file_managed', 'f')
->condition('uri', rawurldecode($uri))
->fields('f', array('fid'))
->execute()
->fetchField();
if ($fid) {
$file = file_load($fid);
if (filefield_sources_element_validate($element, $file)) {
$item = array_merge($item, (array) $file);
}
}
else {
form_error($element, t('The selected file could not be used because the file does not exist in the database.'));
}
// No matter what happens, clear the value from the file path field.
$item['filefield_imce']['file_path'] = '';
}
}
Comments
imce_filefield
http://drupal.org/project/imce_filefield check this new ufku module ! It's nice!
Pages
Add new comment