sz ashik
sz ashik

Reputation: 911

phalcon file upload fail

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".

Upvotes: 5

Views: 2191

Answers (1)

Nikolay Mihaylov
Nikolay Mihaylov

Reputation: 3876

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?

Upvotes: 6

Related Questions