我是新来的帕尔康,我被困在文件上传在帕尔康。
所以我搜索了一些基本的东西,但都没有用,我需要一个能帮我解决这个问题的人。
这是我的表单\ volt文件:
<form action="/user/upload" method="post" enctype="multipart/form-data">
<!-- <input type="file" name="my_picture" >
--><label>File</label>
<input type="file" name="upFile" class="form-control">
<input type="submit" class="btn btn-warning" style="margin-top:15px;" value="Upload">
</form>
This is my controller:
```public function uploadAction() { $this->view->disable(); if ($this->request->hasFiles() == true) { foreach ($this->request->getUploadedFiles() as $file){ $upload_dir = DIR . '/../../app/public/img/'; $file->moveTo($upload_dir . $file->getName()); echo $file->getName(), '\n'; } } else { echo 'File not uploaded'; }} 当I var_dump($file);
我拿到了这个:
002.jpg\工发组织(Phalcon\Http\Request\File)#48 (8) { "_name":protected=> string(7) "002.jpg“”_tmp":protected=> string(0) "_size":protected=> int(0) "_type":protected=> string(0) "_realType":protected=> NULL "_error":protected=> int(3) "_key":protected=> string(6) "upFile“_extension":protected=> string(3) "jpg"}
发布于 2019-06-13 07:53:50
,我检查了您的代码,我发现它在某个地方让您感到困惑,所以我在控制器中为您编写了新的代码:
if ($this->request->hasFiles()) {
foreach ($this->request->getUploadedFiles() as $file){
echo $file->getName(), ' ', $file->getSize(), '\n';
$file->moveTo('img/'. $file->getName());
}
}
} 注意:确保写入文件夹名而不是“img/”
https://stackoverflow.com/questions/56575377
复制相似问题