I am making an admin tool, for the site I am making, that allows the admin to make image uploads to a folder at the server, that stores images for a gallery. The file is being uploaded correctly but the image name isn't being placed on the database. The name should be placed at the table "gallery_images", on the "path" field. How can this be fixed?
I am using CakePHP 2.4.4
Controller
<?php
class AdminsController extends AppController{
public $components = array('RequestHandler');
public function admin_index(){
if(!$this->Session->check('Admin')){
$this->Session->setFlash('Está a aceder a uma zona restrita. Por favor faça Login.');
$this->redirect(array(
'controller' => 'admins',
'action' => 'login'));
}
$this->layout='admin_index';
}
public function add_foto() {
if(!$this->Session->check('Admin')){
$this->Session->setFlash('Está a aceder a uma zona restrita. Por favor faça Login.');
$this->redirect(array(
'controller' => 'admins',
'action' => 'login'));
}
$this->layout='admin_index';
$file=$this->request->data['gallery_images']['path'];
if($this->request->is('post') || $this->request->is('put')){
$this->Admin->create();
$this->Admin->save($file);
move_uploaded_file($this->data['gallery_images']['path']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/html/PushUp_app/app/webroot/img/gallery/' . $this->data['gallery_images']['path']['name']);
if($this->Admin->save($this->request->data)){
$this->Session->setFlash(__('Ficheiro carregado com sucesso!'));
}
}
//$this->Admin->id = $id;
//$this->Post->save($data=array($this->data['Admins']['path']), $params=array('fieldList'=>'path'));
//$this->Post->saveField('path', $this->data['Admins']['path']);
/*if ($this->ModelName->save($this->request->data)) {
$this->Session->setFlash('Data Saved!');
}*/
//if($this->request->is('post')){
// $this->Admin->save($this->request->data);
//}
//}
}
}
?>
View
<h2>Adicionar Fotografia</h2>
<?php
echo "<br>";
echo $this->Form->create('Admin',array('type'=>'file'));
echo $this->Form->file('gallery_images.path');
echo "<br>";
//echo $this->Form->submit();
echo $this->Form->end('Guardar');
//validação é feita no AdminsController
?>