【问题标题】:how can i upload a video and it saved to a folder in codeigniter?如何上传视频并将其保存到 codeigniter 的文件夹中?
【发布时间】:2016-04-24 18:51:18
【问题描述】:

我是 Codeigniter 的新手。我需要帮助上传图片和视频并将其保存到文件夹和数据库。

这是我的控制器

public function upload()
{   
    $this->m_upload->upload();  
    $this->upload_gambar(); 
}

public function upload_gambar()
{
    //load the helper
    $this->load->helper('form');
    $config['upload_path'] = 'assets/gallery/images';

    $config['allowed_types'] = 'gif|jpg|png|mp4';
    $config['max_size'] = '';

    $this->load->library('upload', $config);    
    $this->upload->initialize($config);
    $this->upload->set_allowed_types('*');
    $data['upload_data'] = '';
    $this->upload->do_upload('uploadan');

    redirect(c_upload);
}

这是我的模型

public function upload()
{
    $title = $this->input->post('title');
    $details = $this->input->post('details');
    $type = $this->input->post('gallery');
    $picture = $_FILES['uploadan']['name'];

    $data = array(
        'url' => $picture,
        'title' => $title,
        'details' => $details,
        'category' => $type
    );

    $this->db->insert('gallery', $data);
}

我已经在 php.ini 中设置了 upload_max_filesize 和 post_max_size 但它仍然无法正常工作。请帮我解决这个问题。谢谢你

【问题讨论】:

  • 那是 php 代码。但是如果我想通过 codeigniter 来做呢?
  • 如果一切都失败了,你总是可以look at the manual
  • 欢迎来到 SO。 it still not working:请编辑问题并描述会发生什么(发布错误消息,如果有的话?)
  • @RiggsFolly 当前和旧的codeigniter 文档现在位于codeigniter 主网站codeigniter.com/docs

标签: php codeigniter


【解决方案1】:

试试这个

在控制器中

$configVideo['upload_path'] = 'assets/gallery/images'; # check path is correct
$configVideo['max_size'] = '102400';
$configVideo['allowed_types'] = 'mp4'; # add video extenstion on here
$configVideo['overwrite'] = FALSE;
$configVideo['remove_spaces'] = TRUE;
$video_name = random_string('numeric', 5);
$configVideo['file_name'] = $video_name;

$this->load->library('upload', $configVideo);
$this->upload->initialize($configVideo);

if (!$this->upload->do_upload('uploadan')) # form input field attribute
{
    # Upload Failed
    $this->session->set_flashdata('error', $this->upload->display_errors());
    redirect('controllerName/method');
}
else
{
    # Upload Successfull
    $url = 'assets/gallery/images'.$video_name;
    $set1 =  $this->Model_name->uploadData($url);
    $this->session->set_flashdata('success', 'Video Has been Uploaded');
    redirect('controllerName/method');
}

在模型中

public function uploadData($url)
{
    $title = $this->input->post('title');
    $details = $this->input->post('details');
    $type = $this->input->post('gallery');

    $data = array(
        'url'       => $url,
        'title'     => $title,
        'details'   => $details,
        'category'  => $type
    );

    $this->db->insert('gallery', $data);
}

【讨论】:

    【解决方案2】:

    为媒体文件添加 mimes 代码:

    application/config/mimes.php
    

    尤其是 mp4

    【讨论】:

    • 我已经在 mime 上添加了一些类型,如 mp4、avi 等,但它仍然无法正常工作。
    • 使用$this->upload->display_errors() 处理$this->upload->do_upload('uploadan'); 之后的错误,同时使用上传路径作为$config['upload_path'] = './assets/gallery/images';
    猜你喜欢
    • 2013-09-03
    • 2018-10-05
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    相关资源
    最近更新 更多