Created
March 20, 2014 17:42
-
-
Save patrickmaciel/9669574 to your computer and use it in GitHub Desktop.
Salvar uma imagem na tabela gallery_images utilizando o CakePHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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