How to check if file has changed during (hook) form_validate in a form? I have a custom content type, and the relative form for creating/editing contents. It contains a file field. I need to check, during hook

 function mymodule_myform_form_validate($form, $form_state){...}


if the user changed the file with another (while editing the content). This can be done by checking if the fid has changed, and the fid of the new file can be found, for example, in

 $lang_field = $form['my_field']['#language'];
 $file_fid = $form_state['input']['my_field'][$lang_field][0];


but what about the fid of the old file? Exploring form and form_state array i found several occurrences of the old and the new fid, but i am not sure which i'm supposed to use. I am not even certain that the code above is the correct one for retrieving the fid of the new file... There is a standard (safe) way to retrieve these informations?
There are 2 approach we can look into:


Query the DB using db_query in field table, like if your field machine name is field_image, then its field will be field_data_field_image, and get fid of a particular node, in this case fid will be in field_image_fid

SELECT field_image_fid from field_data_field_image WHERE entity_id=NODE_ID


It will get u previous fid, and u can validate


Load Node from nid, either using node_load or entity_load_single, from here you will get your Old FID, as image has not yet been attached to the node, it has only been saved in file_managed Table.