How to save the name of the image from an input file

I have a field type string called image_cover on my database. I have a field type file on my form:

<?php echo $this->Form->create($event, ['type' => 'file']) echo $this->Form->file('image_cover') echo $this->Form->submit('Send') echo $this->Form->end() ?>

On controller $this->request->data('image_cover') is an array with file name, size etc.

I need the value of the image_cover change to only the name of the file.

I'm trying do this on beforeSave but is not working


There are a few ways of doing this, but the easiest to understand is to have an input field that is not part of the schema of your table. For example, instead of image_cover you could have image_file:

echo $this->Form->file('image_file');

Make sure you set image_file in the $_accessible list of fields of your entity. You will be able to access this field in beforeSave so you can store it.

There is this plugin that will do exactly that for you:

Category:php Time:2017-12-03 Views:3

Related post

Copyright (C), All Rights Reserved.

processed in 1.587 (s). 13 q(s)