5

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

sz ashik
  • 881
  • 7
  • 20

1 Answers1

6

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?

Community
  • 1
  • 1
Nikolay Mihaylov
  • 3,868
  • 8
  • 27
  • 32