FriendsOfCake / cakephp-upload

CakePHP: Handle file uploading sans ridiculous automagic
https://cakephp-upload.readthedocs.io/
MIT License
551 stars 255 forks source link

Problem with large files upload #475

Closed feLiruc closed 7 years ago

feLiruc commented 7 years ago

I'm trying to implement a multiple upload in my ticket controller, but I don't know why aparently my navigator is not waiting for the upload to finish(with small files it's okay but with large files the page is apparently not waiting so my code return errors...

This is my error screen.

I already set the field to multiple and send the variable as an array: <?php echo $this->Form->input('anexos[]', ['type'=>'file', 'multiple' => true, 'label' => 'Anexos']); ?>

This is the code for my controller:

public function addacompanhamento()
    {
        $acompanhamento = $this->Tickets->Acompanhamentos->newEntity();
        if ($this->request->is('post')) {
            $acompanhamento = $this->Tickets->Acompanhamentos->patchEntity($acompanhamento, $this->request->getData());
            $acompanhamento->user_id = $this->Auth->user('id');
            $idDoTicket = $acompanhamento->ticket_id;
            $emailDoDonoTicket = $acompanhamento->email_dono_ticket;
            $nomeDoDonoTicket = $acompanhamento->nome_dono_ticket;
            $ticket = $this->Tickets->get($idDoTicket, [
                'contain' => []
            ]);
            $ticket->worktime = $this->atualizaSLA($ticket->lastfollowup, $ticket->situacao, $ticket->worktime);
            $tipoacompanha = $acompanhamento->tipoacompanhamento;

            $ticket->lastfollowup = date("Y-m-d H:i:s");
            $acompanhamento->foiAprovado = null;
            if ($this->Tickets->Acompanhamentos->save($acompanhamento)) {
                if ($this->Tickets->save($ticket)) {
                    foreach ($acompanhamento['anexos'] as $anexo) {
                        $acompanhamentoAnexo = TableRegistry::get('AcompanhamentoAnexos');
                        $anexo2 = $acompanhamentoAnexo->newEntity();
                        $anexo2->acompanhamento_id = $acompanhamento->id;
                        $anexo2->filename = $anexo;
                        $acompanhamentoAnexo->save($anexo2);
                    }
                    if($acompanhamento->user_id!=$ticket->user_id){
                        if($acompanhamento->visivel===1){
                            $this->enviarEmail($idDoTicket, $nomeDoDonoTicket, $emailDoDonoTicket, true, $ticket->titulo, $acompanhamento->texto_acompanhamento,$this->Tickets->Users->get($ticket->responsavel)->nomecompleto);
                        }
                    }

                    $this->Flash->success(__('O acompanhamento foi adicionado.'));

                    return $this->redirect(['controller' => 'tickets', 'action' => $tipoacompanha, $acompanhamento->ticket_id]);
                }
            }else{
                $this->Flash->error(__('Erro ao adicionar acompanhamento. Favor, verificar as informações fornecidas.'));
                return $this->redirect(['controller' => 'tickets', 'action' => $tipoacompanha, $acompanhamento->ticket_id]);
            }
        }
    }
josegonzalez commented 7 years ago

You are either:

This plugin doesn't control any of those things, so you'll need to fix them on your setup.

davidyell commented 7 years ago

Or, if the files are really large, hand off the uploading and processing to a worker process from a queue.

feLiruc commented 7 years ago

Checking the logs I discovered that my problem was with the post_max_size variable in the php.ini Now I need to limit the number of files in the input type="file" Thank you for your attention guys.