phalcon文件上传失败
phalcon file upload fail
我已尝试将文件上传到服务器。但是它不起作用的地方。
这是我的表格。
<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';
}
}
但它总是return "File not uploaded"。
你的php代码是正确的,问题出在你的html。您应该在表单中添加正确的编码:
<form action="index/upload" method="POST" enctype="multipart/form-data">
更多信息在这里:What does enctype='multipart/form-data' mean?
我已尝试将文件上传到服务器。但是它不起作用的地方。 这是我的表格。
<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';
}
}
但它总是return "File not uploaded"。
你的php代码是正确的,问题出在你的html。您应该在表单中添加正确的编码:
<form action="index/upload" method="POST" enctype="multipart/form-data">
更多信息在这里:What does enctype='multipart/form-data' mean?