【问题标题】:Upload File||The filetype you are attempting to upload is not allowed上传文件||您尝试上传的文件类型不允许
【发布时间】:2020-03-11 07:03:26
【问题描述】:

无法将视频存储到服务器。我在 mimes.php 中更改了所有可能的类型,但问题仍然是我的代码。 控制器

    public function frontsliderAdd()
{
    if ($this->session->userdata('admin_logged_in') != TRUE) {
        redirect(base_url() . 'admin/login');
    }
    $data['active'] = 'frontslider';
    if (isset($_POST['addgallery'])) {
        $this->form_validation->set_rules('title', 'Banner Title', 'trim|required');
        $this->form_validation->set_rules('video_url', 'Video Link', 'trim|required');

        if ($_FILES["video_upload"]['name'] == '') {
            $this->form_validation->set_rules('image_upload', 'Image', 'required');
        }

        if ($this->form_validation->run() == TRUE) {
            if ($_FILES["video_upload"]['name']) {

                $config['upload_path'] = './public/uploads/banner_images';

                $config['allowed_types'] = 'jpg|png|jpeg|gif|mp4|avi|mov';

                //$this->load->library('upload', $config);
                $config['max_size'] = '0';
                $this->load->library('upload', $config);
                if (!$this->upload->do_upload('video_upload')) {
                    $error_msg = $this->upload->display_errors();
                } else {
                    $data['video'] = $this->upload->data();
                }
            }
            $data['title'] = $this->input->post('title');
            $data['video_url'] = $this->input->post('video_url');
            $this->load->model('AdminModel');
            $this->AdminModel->saveGallery($data);
        }
    }
    $data['sidebar'] = $this->load->view('admin/sidebar', NULL, TRUE);
    $this->load->view('admin/header');
    $this->load->view('admin/frontslideradd', $data);
    $this->load->view('admin/footer');
}

型号

    public function saveGallery($data)
{
    $array = array(
        'title' => $data['title'],
        'video' => $data['video']['file_name'],
        'video_url' => $data['video_url']
    );
    $this->db->insert('front_slider', $array);
}

查看-添加

 <div class="form-group">
                                        <label for="image_upload">Upload Video</label>
                                        <input type="file" class="form-control" id="video_upload" name="video_upload">
                                        <span class="help-block" style="color: red;"><?php echo form_error('video_upload') ?></span>
                                    </div>

哑剧

'3gp'   =>  array('video/3gp', 'video/3gpp'),
'mp4'   =>  'video/mp4',

没有错误,但成功将其他数据传递到服务器,除了视频请纠正,谢谢提前

【问题讨论】:

  • 听起来像是服务器配置问题。与视频大小相比,您的最大上传大小是多少?如果视频大小超过您可以使用的最大值,那么我建议您研究“分块”解决方案。
  • 正如我所说的 $config['max_size'] = '0';设置为无限制。
  • 除非您自己控制服务器并且可以对其进行配置,否则它永远不会真正无限。您控制服务器还是托管服务器?
  • 我对你的问题是视频文件上传但没有存储在数据库中或者你无法上传视频文件吗?
  • 如果它是托管服务器,那么您可能会在他们的知识库中找到“最大上传大小”(如果有)。但是,如果它是服务器配置问题,那么在没有解决方法的情况下,任何编程客户端或 PHP 都无法解决您的问题。因此,我提到了“分块”。研究该关键字。

标签: javascript php jquery ajax codeigniter


【解决方案1】:

您将上传数据存储在

$data['image'] = $this->upload->data();

并分配了错误的键

 'video' => $data['video']['file_name'] // Here is your problem 

您应该按如下方式更改您的密钥

'video' => $data['image']['file_name']

希望对你有帮助

【讨论】:

  • 改成你的提案谢谢。但是有同样的问题
  • print_r($this->db->last_query);检查到底发生了什么
【解决方案2】:

文件上传出错时停止以获取确切的错误

 if (!$this->upload->do_upload('video_upload')) {
             $error_msg = $this->upload->display_errors(); // Make exit here 
             print_r($error_msg);
             exit;
            } else {
                $data['video'] = $this->upload->data(); 
                $data['title'] = $this->input->post('title');
               $data['video_url'] = $this->input->post('video_url');
               $this->load->model('AdminModel');
               $this->AdminModel->saveGallery($data)
            }

【讨论】:

  • 感谢您的建议。显示您尝试上传的文件类型不允许。
  • @AvikBanerjee 将您的问题标题更改为此 The filetype you are attempting to upload is not allowed 并提及视频文件扩展名。
  • 您应该在 $config['allowed_types'] = 'jpg|png|jpeg|gif|mp4|avi|mov';检查文件的扩展名@AvikBanerjee
  • @GetSet 好的。它的.mp4
  • @BoominathanElango 上面的最后一条评论是您(Avik Banerjee)现在应该前进的方向。您可能需要配置$config['allowed_types']
猜你喜欢
  • 2017-08-18
  • 2012-04-06
  • 2014-12-30
  • 2011-11-21
  • 2011-06-08
  • 2012-04-22
  • 2023-04-07
  • 2016-06-06
  • 1970-01-01
相关资源
最近更新 更多