phalcon - 文件上传不起作用或在 phalconphp 中有一些问题
问题描述
我是 phalcon 的新手,我被困在 phalcon 中的文件上传。
所以我用谷歌搜索了一些基本的东西,但没有一个有用,我需要有人能帮我解决这个问题
这是我的表格 | 伏特文件:
<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';
}
}
当我 var_dump($file);
我懂了 :
002.jpg\nobject(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"}
解决方案
我检查了你的代码,发现它在某个地方让你感到困惑,所以我写了一个新的代码来替换你的控制器:
if ($this->request->hasFiles()) {
foreach ($this->request->getUploadedFiles() as $file){
echo $file->getName(), ' ', $file->getSize(), '\n';
$file->moveTo('img/'. $file->getName());
}
}
}
注意:确保写下您的文件夹名称而不是“img/”
推荐阅读
- python - Pandas GroupBy 和 Sum python
- ios - 如何从“for循环”返回字符串?Objective-C iOS
- java - 如何从 AlarmManager BroadcastReceiver 调用 MainActivity 方法?
- c# - 在调试窗口中看不到任务正在运行 - Visual Studio 2019
- c# - Visual Studio 中的 .net 核心适用于控制台应用程序,但不适用于 wpf 或 winforms
- python - 同时使用 python 2 和 3 的项目的虚拟环境?
- laravel - Laravel 7查询构建器忽略新数据
- iframe - 如何从 postMessage() 访问数据?
- swift - Swift、核心数据和Int16加法问题
- javascript - 触发云功能时“TypeError:无法读取未定义的属性'孩子'”