I am having problem while trying to upload a picture in a form that also has other required field. So if I dont enter anything on the required field and upload the picture, I lose the picture that's uploaded (during the form validation the picture is no longer there). I can't print it anywhere in form_state and all. How can I have a file upload inside a form with other form elements which are required? I dont want user to upload the picture again if the user forgets to enter the info in the other required field.
Any ideas?
    function form() {
    $form['#attributes'] = array('enctype' => "multipart/form-data");
    //'upload' will be used in file_check_upload()
    $form['upload'] = array('#type' => 'file');
    $form['my_require_field'] = array(
        '#type' => 'textfield',
        '#title' => t('Enter code here'),
        '#default_value' => 1,
        '#size' => 20,
        '#required' => TRUE
      );
    }
    function form_validate() {
     if(!file_check_upload('upload')) {
     form_set_error('upload', 'File missing for upload.');
    }
    }
    function form_submit() {
     $file = file_check_upload('upload');
    }
 
                        
You should use the managed_file type id you are using Drupal 7
In your submit handler you can write following:
Hope this will help!