0

I am new to CodeIgniter and was working on downloading a file. However, I want to download a file that resides on my local machine, I am able to locate the file by providing the path, also the file gets downloaded with a File type, However, I want my file to be in .csv format

Here goes my Controller's download function:

public function download()
{   
        $state_id=$this->input->post('state'); // gets me the state-id from viw's dropdown
        $this->load->helper('download'); // Load download helper
        $file="C:\\Users\usernew\\Desktop\\New folder\\".$state_id.".csv";
        $filename=$state_id.'.csv';
        
    
        if (file_exists($file))
        {
                $data = file_get_contents($file);       //check file exists 
                force_download($fileName,$data);
            }
            else{
                echo"not working!";
            }    
        }   

Where am I going wrong?

3

1 Answer 1

1

As the force_download() function accepts the file name to be set and the data to insert into that file, as you have the data in that file already, you just need to download it. so, You should use the for_download() function like this:

force_download($file,NULL);

This will solve your problem :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.