使用 codeiginter 帮助上传文件
我正在尝试使用 PHP 和 codeigniter 上传文件。我的问题是返回错误
您没有选择要上传的文件。
我正在使用以下代码,
$config['upload_path'] = "./media/uploads/cv";
$config['allowed_types'] = 'pdf|doc|docx';
$config['max_size'] = '1000';
$this->upload->initialize($config);
$this->upload->do_upload('cvfile');
if($this->upload->display_errors())
{
$data['error'] = $this->upload->display_errors();
die(print_r($data['error']));
$this->template->build('/users/candidate', $data);
return;
}
else
{
die(print_r($this->upload->data()));
}
在我的 HTML 中,我有一个多部分表单,在该表单中我使用以下代码,
<input type="file" class="small" id="cvfile" value="" name="cvfile">
为什么我会收到上述错误?
I am trying to upload a file using PHP and codeigniter. My problem is that I am getting an error returned
You did not select a file to upload.
I am using the following code,
$config['upload_path'] = "./media/uploads/cv";
$config['allowed_types'] = 'pdf|doc|docx';
$config['max_size'] = '1000';
$this->upload->initialize($config);
$this->upload->do_upload('cvfile');
if($this->upload->display_errors())
{
$data['error'] = $this->upload->display_errors();
die(print_r($data['error']));
$this->template->build('/users/candidate', $data);
return;
}
else
{
die(print_r($this->upload->data()));
}
In my HTML I have a multipart form and with in that form I am using the following code,
<input type="file" class="small" id="cvfile" value="" name="cvfile">
Why would I be getting the above error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这说明 PHP 函数
is_uploaded_file
表明名为cvfile
的上传文件不存在。您应该检查您的 multipart/form 声明并验证其是否有效,并确保您的 PHP 设置允许您将上传的文件写入临时文件夹。That says that the PHP function
is_uploaded_file
indicated that the upload file with the namecvfile
didn't exist. You should check your multipart/form declaration and verify that it is valid, and make sure your PHP setup will allow you to write uploaded files to the temp folder.视图:
控制器:
View:
Controller: