I'm using the following code for validating and uploading a file from a form:
function request_form_submit($form, &$form_state) {
$validators = array('file_validate_extensions' => array('png'));
$file = file_save_upload('spectrum', $validators);
if ($file) {
//do stuff
}
Uploading works, but I want to allow only png files to be uploaded. The validation part does not work at all, file uploading is always successful no matter which extension the uploaded file has.
I also tried giving a space separated list of extensions to file_validate_extensions
as mentioned in the documentation, but that didn't change anything.
Any idea what I'm doing wrong here and why this doesn't work at all?