使用 codeiginter 帮助上传文件

发布于 2024-11-06 00:21:31 字数 965 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

追我者格杀勿论 2024-11-13 00:21:31

这说明 PHP 函数 is_uploaded_file 表明名为 cvfile 的上传文件不存在。您应该检查您的 multipart/form 声明并验证其是否有效,并确保您的 PHP 设置允许您将上传的文件写入临时文件夹。

That says that the PHP function is_uploaded_file indicated that the upload file with the name cvfile 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.

遥远的她 2024-11-13 00:21:31

视图:

<?php echo form_open_multipart('home/.....');?>//going to next page 
      <input type="file" name="cvfile" />
</form>

控制器:

$config['upload_path']   = './path'; // put here your path 
$config['allowed_types'] = 'pdf|doc|docx';  
$config['max_size']      = '4096';      

$this->load->library('upload', $config);
$this->upload->display_errors('', '');

if (!$this->upload->do_upload("cvfile")) {
    echo $this->upload->display_errors(); die();
    $this->data['error'] = array('error' => $this->upload->display_errors());
} else {
    $upload_result = $this->upload->data();
    print_r($upload_result['file_name']);//or print any valid
}

View:

<?php echo form_open_multipart('home/.....');?>//going to next page 
      <input type="file" name="cvfile" />
</form>

Controller:

$config['upload_path']   = './path'; // put here your path 
$config['allowed_types'] = 'pdf|doc|docx';  
$config['max_size']      = '4096';      

$this->load->library('upload', $config);
$this->upload->display_errors('', '');

if (!$this->upload->do_upload("cvfile")) {
    echo $this->upload->display_errors(); die();
    $this->data['error'] = array('error' => $this->upload->display_errors());
} else {
    $upload_result = $this->upload->data();
    print_r($upload_result['file_name']);//or print any valid
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文