Skip to content

Instantly share code, notes, and snippets.

@patrickmaciel
Created March 20, 2014 17:42
Show Gist options
  • Save patrickmaciel/9669574 to your computer and use it in GitHub Desktop.
Save patrickmaciel/9669574 to your computer and use it in GitHub Desktop.
Salvar uma imagem na tabela gallery_images utilizando o CakePHP
<?php
class AdminController extends AppController {
// .. outras actions aqui
public function admin_upload_image() {
$this->layout = 'admin_index';
if($this->request->is('post') || $this->request->is('put')) {
$file = array(
'GalleryImage' => array(
'path' => $this->request->data['gallery_images']['path']['name']
)
);
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']);
$this->loadModel('GalleryImage');
$this->GalleryImage->create();
if ($this->GalleryImage->save($file)) {
echo 'Salvou';
exit;
} else {
echo 'Não salvou';
exit;
}
}
}
}
<?php
App::uses('AppModel', 'Model');
/**
* GalleryImage Model
*/
class GalleryImage extends AppModel {
public $displayField = 'path';
public $useTable = 'gallery_images';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment