diff --git a/config/file_upload_settings.php b/config/file_upload_settings.php index 2b08d42..ade4420 100644 --- a/config/file_upload_settings.php +++ b/config/file_upload_settings.php @@ -187,7 +187,14 @@ class FileUploadSettings { * 'fileNameFunction' => 'md5' * 'fileNameFunction' => 'crc32' */ - 'fileNameFunction' => false + 'fileNameFunction' => false, + + /** + * To allow Model to be saved without the file fields if no file is uploaded. + * + * For use when using FileUpload directly on an existing Model. + */ + 'allowEmpty' => false ); } diff --git a/models/behaviors/file_upload.php b/models/behaviors/file_upload.php index 2fced9f..8c7c346 100644 --- a/models/behaviors/file_upload.php +++ b/models/behaviors/file_upload.php @@ -76,7 +76,12 @@ function beforeSave(&$Model){ unset($Model->data[$Model->alias][$this->options[$Model->alias]['fileVar']]); } else { - unset($Model->data[$Model->alias]); + if ($this->options[$Model->alias]['allowEmpty']) { + //unset only the file portion of the model so that the rest fo the model's data will be saved + unset($Model->data[$Model->alias]['file']); + } else { + unset($Model->data[$Model->alias]); + } } } return $Model->beforeSave();