26 January 2012

How to change file name programmatically after file is saved in Drupal 7.

Source code viewer
  1. // file name showed to user in Drupal
  2. $file = file_load($fid);
  3. $file->filename = $value;
  4. file_save($file);
  5.  
  6. // real file name in sites/default/files
  7. $file = file_load($fid);
  8. file_move($file, file_default_scheme().'://some_directory/'.$value);
Programming Language: PHP