Index: field_file.inc =================================================================== RCS file: /cvs/drupal/contributions/modules/flexinode/field_file.inc,v retrieving revision 1.13.2.2 diff -u -r1.13.2.2 field_file.inc --- field_file.inc 2 Feb 2007 12:02:21 -0000 1.13.2.2 +++ field_file.inc 16 Apr 2007 08:37:38 -0000 @@ -11,7 +11,7 @@ $form[$fieldname] = array( '#type' => 'file', '#title' => t($field->label), - '#description' => ($node->$fieldname ? t('"%filename" has been uploaded. If you upload another file, the current file will be replaced.', array('%filename' => $node->$fieldname->filename)) : '') . t($field->description), + '#description' => ($node->$fieldname ? t('"%filename" has been uploaded. If you upload another file, the current file will be replaced.', array('%filename' => $node->$fieldname->filename)) : '') . t($field->description). t('The file is limited to %kbKB and a file type of %ext.', array('%ext' => $field->options[1], '%kb' => $field->options[2])), '#required' => $field->required, '#weight' => $field->weight, ); @@ -51,7 +51,18 @@ function flexinode_field_file_validate($field, $node) { $fieldname = 'flexinode_'. $field->field_id; - return file_check_upload($fieldname); + if($file = file_check_upload($fieldname)) { + $pathinfo = pathinfo($file->filename); + if ($field->options[1]!=NULL && (!in_array($pathinfo['extension'], explode(',', $field->options[1]) ))) { + form_set_error($fieldname, t('The file has the wrong extension and/or type.')); + } + else if ($field->options[2]!=NULL && @filesize($file->filepath) > ($field->options[2] * 1000)) { + form_set_error($fieldname, t('The uploaded image is too large; the maximum file size is %num kB.', array('%num' => $field->options[4]))); + } + } + elseif(!empty($node->$fieldname)) { + form_set_error($fieldname, t('The file upload was not successful.')); + } } function flexinode_field_file_execute($field, $node) { @@ -64,6 +75,32 @@ } } +function flexinode_field_file_config($field, $edit) { + $form = array(); + + $form['options'] = array( + '#type' => 'fieldset', + '#title' => t('Options'), + '#description' => t('Limitations for files to upload.'), + ); + $form['options'][1] = array( + '#type' => 'textfield', + '#title' => t('Allowed extensions'), + '#default_value' => $field->options[1], + '#description' => t('Comma separated list of allowed file extensions.'), + '#required' => TRUE, + ); + $form['options'][2] = array( + '#type' => 'textfield', + '#title' => t('Maximum file size'), + '#default_value' => $field->options[2], + '#description' => t('Maximum file file size, in kB. Leave blank for the maximum upload size allowed in your webserver configuration.'), + ); + + return $form; +} + + function flexinode_field_file_format($field, $node, $brief = 0) { $fieldname = 'flexinode_'. $field->field_id; $file = is_object($node->$fieldname) ? $node->$fieldname : unserialize($node->$fieldname);