I've been trying to get validators for a file_save_upload call to work without much luck. Here's the code I'm working with:
<?php
function wwguser_edit(){
$form['report_logo'] = array('#type' => 'file',);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
}
function wwguser_edit_submit($form, &$form_state) {
$validators = array(
'file_validate_extensions' => array( 'jpg jpeg' ),
'file_validate_image_resolution' => array( '160x70' ),
'file_validate_size' => array(50*1024, 0),
);
if ($file = file_save_upload('report_logo', $validators, file_directory_path())) {
file_set_status($file, FILE_STATUS_PERMANENT);
}
}
?>
Using the above code I'm able to upload files without issue to the correct directory and entries are created in the {files} table with a status of 1 (permanent). However, my validators aren't processed at all so I'm allowed to upload any kind of file I choose at any file size. The only thing I've been able to get to work is swapping the "file_validate_extensions" for a "file_validate_is_image". Using that validator works as expected (an error is thrown if I select a .txt file for example) but my size and resolution validators still aren't processed. I'm assuming it's a syntax error as the "file_validate_is_image" works fine and the file uploads correctly.
Can anyone help me out with this?
Thanks.
Comments
Forgot to add that I have
Forgot to add that I have added
to my form. Also, I've gotten the resolution validator to work but still no luck with extension or size.
Found the problem. Was
Found the problem. Was testing as the administrator and per the API - "This check is not enforced for the user #1."