1

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'

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Are you storing the file using the file field? If so, check out the "File (Field) Paths" module. http://drupal.org/project/filefield_paths

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.