I am able to successfully upload files using managed_file. The file is saved in the correct directory and the record shows up in the file_managed table.

$form['image'] = array(
    '#title' => t('Image'),
    '#type' => 'managed_file',
    '#default_value' => (isset($foo->image->fid) ? $foo->image->fid : ''),
    '#upload_location' => 'public://foo_images/'

But when I edit the form, it still shows the Upload button, similar to the Create page before I have uploaded a file. How do I make the edit page look like I have already uploaded a file for that particular entity?

1 Answer 1


Inspecting the $foo variable showed that I was supposed to use just $foo->image instead of $foo->image->fid.

Probably because I have the following lines in my _form_submit:

if (isset($form_state['values']['image'])) {
    $file = file_load($form_state['values']['image']); 
    $file->status = FILE_STATUS_PERMANENT;
    file_usage_add($file, 'foo', 'foo', $foo->tkid);

    $foo->image = $file->fid;

Notice the part that says $foo->image = $file->fid;

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.