Managed file: What is the proper way of setting #default_value? $form['picture']['file'] = array(
  '#type' =&gt; 'managed_file',
  '#title' =&gt; t('picture'),
  '#description' =&gt; t('Allowed extensions: gif png jpg jpeg'),
  '#default_value' =&gt; (isset($foo-&gt;picture-&gt;fid) ? $foo-&gt;picture-&gt;fid : ''),
  '#upload_location' =&gt; variable_get('picture_upload_location'),
  '#upload_validators' =&gt; array(
    'file_validate_extensions' =&gt; array('gif png jpg jpeg'),
    // Pass the maximum file size in bytes
    'file_validate_size' =&gt; array(MAX_FILE_SIZE*1024*1024),
  ),
);


I have the above code snippet from here.  It's very useful, however I'm having a hard time setting #default_value. 

What is $foo?  Where is it set and how can I change it?  Will I use the image uploaded on the other pages (coded in the same module).
Welcome to Drupal Answers. You just need to pass the fid integer value to the default value. To better understand what is fid see below description.


  fid is Unique File id that is stored in the database for each and
  every uploaded file using Drupal File System. 


So, if you want to set default image then it should be uploaded via Drupal File System. Ideally, you need to store fid of the uploaded file in a variable using variable_set in submit handler and do variable_get in default value to set fid. That's it !!

Hope it answers :-)