我已经尝试将文件上传到服务器。但在不起作用的地方。这是我的表格。
<form action="index/upload" method="POST">
<label>File</label>
<input type="file" name="upFile">
<input type="submit" name="upload">
</form>
这是我的控制器
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';
}
}
但它总是返回"文件未上传"。
您的php代码是正确的,问题在于您的html。您应该在表单中添加正确的编码:
<form action="index/upload" method="POST" enctype="multipart/form-data">
这里的更多信息:什么是enctype=';多部分/表单数据';意思是