我想在codeigniter中下载文件

时间:2014-12-09 11:50:12

标签: codeigniter

通过这种方式我可以上传图片和pdf .. 但我想从我的视图下载pdf或图像...请有人给我从视图下载pdf或图像的代码..给我完整的代码

 public function save_about_1() {
    $about_1_image_info = $this->w_model->select_about_1_image();
    $image_path = explode(base_url(), $about_1_info->about_1_link, 2);
    unlink($image_path[1]);
    $this->sa_model->delete_about_1($about_1_info->about_1_id);
    $data = array();
    /* Uplod start */
    $config['upload_path'] = 'images/about_1/';
    $config['allowed_types'] = 'gif|jpg|png|pdf|doc|xml';
    $config[ 'overwrite'] = TRUE;
    $config['max_size'] = '10000kb';
    $config['max_width'] = '100240';
    $config['max_height'] = '76800';
    $error = array();
    $fdata = array();
    $this->load->library('upload', $config);

    if (!$this->upload->do_upload('about_1_link')) {
        $error = $this->upload->display_errors();
        $edata = array();
        $edata['error_message'] = $error;
        $this->session->set_userdata($edata);
        redirect('super_admin/about_1');
    } else {
        $fdata = $this->upload->data();
        $data['about_1_link'] = base_url() . $config['upload_path'] . $fdata['file_name'];
        $this->sa_model->save_about_1_info($data);
        $sdata = array();
        $sdata['message'] = "Saved Image Successfully";
        $this->session->set_userdata($sdata);
        redirect('super_admin/about_1');
    }
}

1 个答案:

答案 0 :(得分:0)

您可以使用CI下载帮助程序。

$data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
$name = 'myphoto.jpg';

force_download($name, $data); 

来自CI用户指南。 https://ellislab.com/codeigniter/user-guide/helpers/download_helper.html