You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When adding file upload fields to existing model, if no file is supplied, the entire Model portion of the array is unset #6
if no file has been uploaded (either because none was chosen or one already exists) then it unsets the entire model rather than just the [file] portion
this patch introduces a allowEmpty option which defaults to false, but if true will only unset the [file] portion allowing any changes to the [name] to be saved
diff --git a/config/file_upload_settings.php b/config/file_upload_settings.php
old mode 100644
new mode 100755
index 2b08d42..ea2cc8f
--- 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
old mode 100644
new mode 100755
index 040b5d1..21c6418
--- a/models/behaviors/file_upload.php
+++ b/models/behaviors/file_upload.php
@@ -76,7 +76,12 @@ class FileUploadBehavior extends ModelBehavior {
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();
Activity