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

[eluser]veledrom[/eluser]
Hi,

I can upload and download the image but when I open downloaded image, nothing shows up. It says "no preview". However, I can access the image through browser by typing the path.
Code:
public function do_downloadfile()
    {
        $exist = @fopen(base_url() . 'upload/' . $this->uri->segment(3), "r");
    
        if($exist)
        {
            $this->load->helper('download');
            
            //$filepath = './upload/' . $this->uri->segment(3);
            $filepath = base_url() . 'upload/' . $this->uri->segment(3);
            
            //$data = file_get_contents($filepath);
            $data = fopen($filepath, "wb");
            $name = $this->uri->segment(3);
            
            force_download($name, $exist);
        }
        else
        {
            echo $this->uri->segment(3) . " doesn't exist!";
        }
    }


Upload folder is under main root.
http://localhost/CI/upload/12743552b2871...5dd6fe.JPG

Is file being corrupted when downloaded? Neither fopen() nor file_get_contest() work...

Thanks
#2

[eluser]toopay[/eluser]
Code:
force_download($name, $exist);
Is this actual code or typo error? Because the second parameter should be the string data.
#3

[eluser]veledrom[/eluser]
Sorry I was testing with many possibilities. It is actually
Code:
force_download($name, $data);
#4

[eluser]Unknown[/eluser]
So far,So good.
#5

[eluser]veledrom[/eluser]
I added my controller and view file for you to have a better idea. Please help me I am desperate to do this.

Upload and download successful but the image I download later on is corrupted I think. Nothing shows up.

Thanks

Note: Just create a folder called "upload" in main root of CI.




Theme © iAndrew 2016 - Forum software by © MyBB