how can i prefix a name to the uploaded file name in drupal?
Eg: If my uploaded file name is 'example.pdf' after click upload, i want to rename it as 'myprefix_example.pdf'
how can i prefix a name to the uploaded file name in drupal?
Eg: If my uploaded file name is 'example.pdf' after click upload, i want to rename it as 'myprefix_example.pdf'
Code example:
function [MODULE]_form_alter(&$form, &$form_state, $form_id)
{
if($form_id == "MY_FORM_ID")
{
$form['#submit'] = 'my_new_submit_callback';
}
}
function my_new_submit_callback($form, &$form_state)
{
$uploaded_file = file_load($form_state['values']['my_file_field']);
$uploaded_file->name = "suffix_" . $file->name;
file_save($uploaded_file);
}
The code isn't tested, let me know if it didn't work.
Are you storing the file using the file field? If so, check out the "File (Field) Paths" module. http://drupal.org/project/filefield_paths