Populate a file field on edit form I need to populate the file field with a value from the database (when editing a database row).

This is the code for the file field.

$form['file'] = array(
'#type' =&gt; 'file',
'#title' =&gt; t('Image'),
'#description' =&gt; t('Upload a file, allowed extensions: jpg, jpeg, png, gif'),
);


The variable $icon contains the value (e.g. icon.png).

In Drupal 7 I made this work with:

  '#type'         =&gt; 'managed_file',
  '#description'  =&gt; t('Icon file may be a jpg, bmp, gif or png format.'),
  '#default_value' =&gt; $default_icon,


How can I do this in Drupal 6?
I ended up using this

if ($form_state['storage']['file'] != '0') {
  $file = file_save_upload('file', array(
    'file_validate_extensions' =&gt; array('png gif jpg jpeg'),
    'file_validate_is_image' =&gt; array(),
  ));

  // If the file passed validation:
  if (isset($file-&gt;filename)) {
    // Move the file, into the Drupal file system
    if (file_move($file, $file-&gt;filename)) {
      // Update the new file location in the database.
      drupal_write_record('files', $file, 'fid');
      // Save the file for use in the submit handler.
      $form_state['storage']['file'] = $file;
    }
    else {
      form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
    }
  }

  $file = $form_state['storage']['file'];
  // We are done with the file, remove it from storage.
  unset($form_state['storage']['file']);
  // Make the storage of the file permanent
  file_set_status($file, FILE_STATUS_PERMANENT);
}

$fid = $file-&gt;fid;
$icon = $file-&gt;filename;

if (!isset($fid)) { 
  $fid = $form['fid']['#value']; 
}

if (!isset($icon)) { 
  $icon = $form['icon']['#value']; 
}

$id = $form['id']['#value'];
$url = $form['url']['#value'];
$title = $form['title']['#value'];