Welcome Guest, Not a member yet? Register   Sign In
Can't download file that has no extension
#1

[eluser]dallen33[/eluser]
Code:
function download()
    {
        if (!$this->dx_auth->is_logged_in()):  
            return FALSE;
        else:
            $query = $this->db->get_where('attachments', array('id' => $this->uri->segment(3)));
            $row = $query->row();
            $data = file_get_contents($this->config->item('attachment_dir', 'booking').$row->attach_id.'/'.$row->name);
            $name = $row->name;
            force_download($name, $data);
        endif;
    }
Pretty basic code to force_download a file. Downloads every file, but if there's no extension, I just get a blank screen. Any ideas why?
#2

[eluser]TheFuzzy0ne[/eluser]
Yes. force_download() uses the file extension to figure out what headers to send to the client, so it know's the type of file it's receiving.
#3

[eluser]Dam1an[/eluser]
That makes sense, but I'd assume there would be a sensible default :-S
Does that mean it would also fail for an unknown extension or is it just failing with no extension as it exist prematurely? (I could probably just look in the code to find out lol)
#4

[eluser]TheFuzzy0ne[/eluser]
You'll have to send the headers manually. What's the file type? just about every file on a Windows system has an extension, this makes it easier for both the user and the OS to distinguish what should be done with that file.
#5

[eluser]Dam1an[/eluser]
Its common for text files in Linux to not have an extension, especially stuff like readme




Theme © iAndrew 2016 - Forum software by © MyBB