Welcome Guest, Not a member yet? Register   Sign In
Image download problem
#1

[eluser]veledrom[/eluser]
Hi,

I can upload and download an image but there is a problem with download. After download, I cannot open the image. I get an error which says "File is not in correct format .....". I simply cannot see the image.

Please give me a hand.

Thanks in advance
Code:
class Fileupload extends CI_Controller{

    public function __construct()
    {
        parent::__construct();
        
        $this->load->helper('url');
    }

    public function index()
    {
        // Page basics
        $data['title'] = "Upload";
        $data['heading'] = "Upload file";
        $data['upload_error'] = NULL;
        
        // Helper for <form...><form>
        $this->load->helper('form');
        
        $this->load->view('fileupload_view.php', $data);
    }
    
    
    
    public function do_uploadfile()
    {
        // Page basics
        $data['title'] = "Upload";
        $data['heading'] = "Upload success";
        
        // Helper for file displaying
        $this->load->helper('directory');
        
        $config['upload_path'] = './upload/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $config['encrypt_name']  = TRUE;
        

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

        if(! $this->upload->do_upload())
        {
            $data['upload_error'] = array('error' => $this->upload->display_errors());

            $this->load->view('fileupload_view.php', $data);
        }
        else
        {
            $data['upload_success'] = array('upload_data' => $this->upload->data());
            
            $uploads = directory_map('./upload/');
            $data['uploads'] = $uploads;

            $this->load->view('fileupload_success_view.php', $data);
        }
    }
    
    public function do_downloadfile()
    {
        $this->load->helper('download');
        
        //$filepath = 'D:\upload\\' . $this->uri->segment(3);
        $filepath = base_url() . 'upload/' . $this->uri->segment(3);
        
        $data = file_get_contents($filepath);
        $name = $this->uri->segment(3);
        
        force_download($name, $data);
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB