Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phalcon file upload fail

Tags:

php

phalcon

I have tried to upload file into server. But where it doesn't work that. This is my form.

<form action="index/upload" method="POST">
    <label>File</label>
    <input type="file" name="upFile">
    <input type="submit" name="upload">
</form>

This is my controller

public function uploadAction()
{
    $this->view->disable();
    if ($this->request->hasFiles() == true) {
        foreach ($this->request->getUploadedFiles() as $file){
               echo $file->getName(), ' ', $file->getSize(), '\n';
        }
    } else {
        echo 'File not uploaded';
    }
}

But it always return "File not uploaded".

like image 509
sz ashik Avatar asked May 16 '16 08:05

sz ashik


1 Answers

Your php code is correct, the problem lies in your html. You should add the correct encoding to your form:

<form action="index/upload" method="POST" enctype="multipart/form-data">

More info here: What does enctype='multipart/form-data' mean?

like image 50
Nikolay Mihaylov Avatar answered Nov 10 '22 00:11

Nikolay Mihaylov