milesj/cake-uploader — Issue #38: File uploads which are not required
Author: blaisethom
Created: 2012-02-01 11:38:54+00:00
State: open

Hi,

I was having some problems with having a field where the file upload is not required. If a file is present I do want the save to fail if the file upload fails so I don't want to set stopSave to false. However, if the file is left blank then the system thinks it has failed. I think you can solve this by having a required feature in the list of settings for the AttachmentBehavior and then change one line of the beforeSave method:

Replace
if ($attachment['stopSave'] ) {

with
if ($attachment['stopSave']
&& !($attachment['required'] == false && strlen($file['name']) == 0)) {

Thanks!