文件上传不工作或在 phalconphp 中有一些问题
file upload not working or has some issue in phalconphp
我是 phalcon 的新手,我被困在 phalcon 的文件上传中。
所以我用谷歌搜索了一些基本的东西,但 none 的那些有用,我需要有人可以帮助我解决这个问题
这是我的表格 |伏特文件:
<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/'
我是 phalcon 的新手,我被困在 phalcon 的文件上传中。
所以我用谷歌搜索了一些基本的东西,但 none 的那些有用,我需要有人可以帮助我解决这个问题
这是我的表格 |伏特文件:
<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/'