dongpou7275 2012-10-25 11:47
浏览 16
已采纳

如果图像是大型CodeIgniter,则图像无效

I'm using this code to download a file:

if ($file_name) {
    $file_url = $file_name;
    header('Content-Type: application/octet-stream');
    header("Content-Transfer-Encoding: Binary");
    header("Content-disposition: attachment; filename=\"" . $file_url . "\"");
    ob_clean();
    flush();
    readfile($file_url);
}

It downloads small file properly but when file size is large then, for Image files (like .jpg) saying Invalid Image. And for .pdf it is says invalid format. I'm using CodeIgniter framework.

$file_name start with https://

  • 写回答

2条回答 默认 最新

  • doujiu1447 2012-10-26 03:08
    关注

    Use the Codeigniter download helper. In your controller:

    $this->load->helper('download');
    $data = file_get_contents($filePath); 
    $extension = end(explode(".", $filePath);
    $name = "myfile" . "." . $extension;
    
    force_download($name, $data);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?