Hi,
I am working on my first project in Drupal and i've a limited knowledge about it.
I am working on a form where i needed to upload images, so, i made use of image module and added following code in my form:
$form['image'] = array(
'#type' => 'file',
'#title' => t('Photo'),
'#description' => t('Click "Browse..." to select an image to upload.'));
and i could see a file upload image in my form, it works really fine but, the only issue i've is that i am unable to add image type validation here in order to restrict users from uploading files other than image files.
The image module is called as:
if(function_exists('image_prepare') && function_exists('image_insert')){
image_prepare($node, 'image');
if($node->images['_original'] != ''){
image_insert($node);
}
}
in image_prepare in image module function i added following code:
if ($image_info['extension']!='jpg' && $image_info['extension']!='png' && $image_info['extension']!='gif' ) {
form_set_error($field_name, t('Uploaded file is not a valid image. Only JPG, PNG and GIF files are allowed.'));
return;
}
control goes here rightly if i echo and exit if i test by uploading a text file, but the form gets submited i.e i don't want to submit the form,but want to return he error.
Please suggest me a solution to this problem,
Thanks,
Kul.
Comments
No help???
No-one available to help at drupal forum?