Skip to content

Model does not update unless image is also uploaded #22

Description

@martinbean

I’ve a model that I’ve added the file upload plugin to as a behavior. My model is set up as follows:

<?php
class Promoter extends AppModel {

    public $name = 'Promoter';
    public $actsAs = array(
        'Containable',
        'FileUpload.FileUpload' => array(
            'allowedTypes' => array(
                'gif' => array(
                    'image/gif'
                ),
                'jpg' => array(
                    'image/jpeg',
                    'image/pjpeg'
                ),
                'png' => array(
                    'image/png'
                )
            ),
            'fields' => array(
                'name' => 'image_filename',
                'type' => 'image_type',
                'size' => 'image_size'
            ),
            'fileNameFunction' => 'sanitizeFileName',
            'required' => false
        )
    );

    public function sanitizeFileName($filename) {
        $imagesDir = 'promoters';
        if (!is_dir($imagesDir)) {
            mkdir($imagesDir);
            chmod($imagesDir, 0755);
        }
        $extension = pathinfo($filename, PATHINFO_EXTENSION);
        return $imagesDir . DS . $this->data[$this->alias]['id'] . '.' . $extension;
    }
}

As you can see, required is set to false. The Promoter model is saved successfully if I also include an image for upload (the values are set in the database row, and the actual image is uploaded to the file system); however, if I don’t select an image to upload, then the database record is not updated despite getting a flash message saying record has been updated.

Any one able to see what the problem is? Have I configured something incorrectly, or is this just because this is the in-development branch and it’s not been addressed yet?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions