veledrom 32 Master Poster

Hi,

I am using this function to download an image that I uploaded before by using Codeigniter. Function successfully downloads it with same name but when I try to open it, I get an error which says "Cannot be opened... file format... is not supported..."

Please help.

Thanks

CONTROLLER:

public function do_downloadfile()
	{
		$this->load->helper('download');
		// $filepath below produces http://localhost/CI/upload/82df53aae33450324bd26cd880d678b5.png
		$filepath = base_url() . 'upload/' . $this->uri->segment(3);
		$data = file_get_contents($filepath);
		$name = $this->uri->segment(3);
		
		force_download($name, $data);
	}

VIEW:

anchor('fileupload/do_downloadfile/82df53aae33450324bd26cd880d678b5.png', 'Download 
');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.