How to rename uploaded file using form API and Drupal managed_file field I make a Drupal Form using FAPI (Drupal 7)
in this form I used managed_file field

$form['image_fid'] = array(
  '#title' =&gt; t('Image'),
  '#type' =&gt; 'managed_file',
  '#upload_location' =&gt; 'public://',
);


I want to rename the uploaded file (make the filename = filename+date)

How can I make something like that
Assuming you know about file status, file_save &amp; file_usage_add.

In your submit callback:

$file = file_load($form_state['values']['image_fid']);
$file-&gt;filename = 'somefilename';
$file-&gt;status = FILE_STATUS_PERMANENT;
file_save($file);
file_usage_add($file, 'yourmodule', 'foo', 1);


More info at the Form API Reference.