I am using cakephp 3.3. I am able to upload single image but it is not getting saved under webroot/uploads. I want to upload multiple images and save it. How can I achieve it? Please provide some inputs. I am very new to PHP programming and this framework.Thanks!
`Images\add.ctp
<?= $this->Form->create($image,['type' => 'file']) ?>
<fieldset>
<legend><?= __('Add Image') ?></legend>
<?php
echo $this->Form->input('path',['type' => 'file']);
?>
</fieldset>`
ImagesController\add
public function add()
{
$image = $this->Images->newEntity();
if ($this->request->is('post')) {
$image = $this->Images->patchEntity($image, $this->request->data);
if ($this->Images->save($image)) {
$this->Flash->success(__('The image has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The image could not be saved. Please, try again.'));
}
}
$properties = $this->Images->Properties->find('list', ['limit' => 200]);
$this->set(compact('image', 'properties'));
$this->set('_serialize', ['image']);
}
Table\ImageTable.php
$validator
->requirePresence('path', 'create')
->notEmpty('path')
->add('processImageUpload', 'custom', [
'rule' => 'processImageUpload'
]);
public function processImageUpload($check = array()) {
if(!is_uploaded_file($check['path']['tmp_name'])){
return FALSE;
}
if (!move_uploaded_file($check['path']['tmp_name'], WWW_ROOT . 'img' . DS . 'images' . DS . $check['path']['name'])){
return FALSE;
}
$this->data[$this->alias]['path'] = 'images' . DS . $check['path']['name'];
return TRUE;
}