# Salvar imagem no banco sql, com outros arquivos criados no bake

**URL:** <https://discourse.cakephp.org/t/salvar-imagem-no-banco-sql-com-outros-arquivos-criados-no-bake/1047>\
**Category:** Need Help\
**Created:** [August 25, 2016, 1:39pm UTC](https://discourse.cakephp.org/t/salvar-imagem-no-banco-sql-com-outros-arquivos-criados-no-bake/1047 "2016-08-25T13:39:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AngeloSoldati](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@AngeloSoldati](https://discourse.cakephp.org/u/AngeloSoldati)\
**Post date:** [August 25, 2016, 1:39pm UTC](https://discourse.cakephp.org/t/salvar-imagem-no-banco-sql-com-outros-arquivos-criados-no-bake/1047/1 "2016-08-25T13:39:38Z")

</div>

Olá pessoal, estou com um problema, criei uma conexão com o banco e salvava dados " news " tranquilamente, porém tive de adicionar imagens a estes dados, e consegui com certo sucesso, mas não consigo vincular os dados, ou seja, no modelo atual, ou eu salvo apenas a imagem, ou apenas os dados, gostaria de salvar os dois, mas não consigo aplicar esta lógica, sou novo no cakephp. Segue a linha de código

```
 */
public function add()
{

      /* Daqui pra baixo salva a Arquivos no banco News*/

    $news = $this->News->newEntity();
    if ($this->request->is('post')) {
        $news = $this->News->patchEntity($news, $this->request->data);
        if ($this->News->save($news)) {
            $this->Flash->success(__('The news has been saved.'));
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error(__('The news could not be saved. Please, try again.'));
        }
    }

    /* Daqui pra baixo salva a imagem no banco News*/

    if (!empty($this->request->data)) {
    $this->Add->send($this->request->data['uploadfile']);}

}`
```

---

<div class="post-metadata">

**Author:** ![AngeloSoldati](https://avatars.discourse-cdn.com/v4/letter/a/dec6dc/32.png) [@AngeloSoldati](https://discourse.cakephp.org/u/AngeloSoldati)\
**Post date:** [August 25, 2016, 1:41pm UTC](https://discourse.cakephp.org/t/salvar-imagem-no-banco-sql-com-outros-arquivos-criados-no-bake/1047/2 "2016-08-25T13:41:33Z")

</div>

Hello everybody, I’m hum problem , I created a connection with the bank and saved data “news” quietly , however tive Total Price: Add Images to these data , and managed with some success , but I can not link the data , IE Current model not , or I saved ONLY an image , or just the data , I would like to save the two , but I can not apply this logic , I am new to CakePHP. Follows a line of code

---

<div class="post-metadata">

**Author:** ![angelorigo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/angelorigo/32/193_2.png) [@angelorigo](https://discourse.cakephp.org/u/angelorigo)\
**Post date:** [August 25, 2016, 5:35pm UTC](https://discourse.cakephp.org/t/salvar-imagem-no-banco-sql-com-outros-arquivos-criados-no-bake/1047/3 "2016-08-25T17:35:48Z")

</div>

> [@AngeloSoldati](#):
>
> otal Price: Add Images to these data , and managed with some success , but I can not link the data , IE Current model not , or I saved ONLY an image , or just the data , I would like to sav

One simple aproach is : saving the filename into the table, and the image on the fileserver. just ensure the image will have a single and original name, using some kind of timestamp processing to not overwrite any files.
