Image File field not getting updated Form function:

$form['upload_photo'] = array(
        '#type' =&gt; 'file',
        '#title' =&gt; t('Upload Your Photo'),
        '#title_display' =&gt; 'before',
        '#states' =&gt; array(
            'visible' =&gt; array(
                ':input[name="testimonial_type"]' =&gt; array('value' =&gt; 'Text'),
            ),
        ),
        '#prefix' =&gt; '&lt;tr&gt;&lt;td&gt;',
        '#suffix' =&gt; '&lt;/td&gt;&lt;/tr&gt;',
    );


Submit function:

$field_collection_item = entity_create('field_collection_item', array('field_name' =&gt; 'field_text_testimonial_info'));
$file_d = $form_state['values']['upload_photo'];
                $file = file_load($file_d);
                $file-&gt;status = FILE_STATUS_PERMANENT;
                file_save($file);
                file_usage_add($file, 'user', 'TYPE', $file-&gt;fid);
                $file_info = image_get_info($file-&gt;uri);
                $file_arr = array(
                'fid' =&gt; $file-&gt;fid,
                );
                $field_collection_item-&gt;field_client_image[LANGUAGE_NONE][0] = $file_arr;
                $field_collection_item-&gt;setHostEntity('user', $user);
                $field_collection_item-&gt;save();


After submit I am getting below error:


Notice: Undefined property: stdClass::$uri in file_save() (line 614 of /public_html/includes/file.inc).
Notice: Undefined property: stdClass::$filename in views_data_export_file_presave() (line 278 of /public_html/sites/all/modules/contrib/views_data_export/views_data_export.module).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => 1 [:db_insert_placeholder_2] => 1535026403 ) in drupal_write_record() (line 7386 of /public_html/includes/common.inc).


Kindly help me to solve it out
Maybe this can help How to upload file in drupal8 forms with form element type file?

I see for your use case it makes more sense to use Managed file type.

A couple of observations, something you should look at,


It seems you are getting SQL errors due to trying to upload a file which is already present in the table, you should check why this happens and perhaps programmatically change the name of the file if it already exists. See file_save_data
Errors from views, not sure where you are trying to submit this form, but it is clearly breaking something in views_data_export or it maybe because of the next point.
Lastly, check the link above for how to properly handle file uploads in form, it looks like file_save($file); is breaking for you due to missing uri