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".
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With