How to validate a file upload field added to a form using hook_form_alter? I am trying to add a file upload field to all story node forms. I tested the code and I am successfully getting the file upload field  on the form. 

$form['my_file_upload'] = array(
    '#attributes' =&gt; array('enctype' =&gt; 'multipart/form-data'),
  '#type' =&gt; 'file',
  '#title' =&gt; t('Image'),
  '#description' =&gt; t('Image should be of minimum 50x50px width and should be of type png or jpg'),
  '#collapsible' =&gt; TRUE,
  '#collapsed' =&gt; TRUE,
  '#size' =&gt; 48,
  '#weight' =&gt; 4,
);


Now the question is How do I validate the file and also how do I retrieve the file after it has passed validation? 

(Site runs on Drupal 6)
What you describe is what the Upload module does: In upload_form_alter() (an implementation of hook_form_alter()), it adds the form element to the node edit forms, and in the form submission handler it adds to the form (upload_node_form_submit()), it handles the uploaded files. With _upload_file_limits(), it checks the user didn't reach the assigned quota; with file_save_upload(), it checks the file passes the validators, and saves the file.

The Upload module, once enabled, allows you to enable the file upload for the content types. For example, for the Page content type, you can enable it at admin/content/node-type/page.



In the node edit form, the form element the Upload module adds appears as in the following screenshot.



If the Upload module is already enabled, and you need a upload form element more, than you should use the CCK module.