Welcome Guest, Not a member yet? Register   Sign In
[Opera browser] CI Download Helper downloads docx files as doc
#1

[eluser]Bikun[/eluser]
Hello,

By some reason in Opera browser CI Download Helper function force_download('filename', 'data') pushes docx files as doc. When I try to download docx file directly, everything works well.

Here is a link to a Word file, downloaded via CI Download Helper:
http://www.tekstiabi.ee/et/download/0ca6...0585ce65ba

Here is a direct link to the same file:
http://www.tekstiabi.ee/uploads/tolge.docx

Here is a code what I use:
Code:
$this->load->helper('download');

$data = file_get_contents("./uploads/".$file_name); // Read the file's contents

force_download($file_name, $data);

The problem exists only in Opera browser.

Any idea what could be wrong?

Thanks in advance.
#2

[eluser]InsiteFX[/eluser]
And were is the file name extension?
#3

[eluser]Bikun[/eluser]
Hi,

Just found a solution myself.

Basically, I checked what headers are returned in case of direct and indirect download.

Direct download:
Code:
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document

Indirect download:
Code:
Content-Type: "application/msword"

Then checked how this content-type is created in helpers/download_helper:
Code:
// Set a default mime if we can't find it
if ( ! isset($mimes[$extension]))
{
$mime = 'application/octet-stream';
}
else
{
$mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
}

Then checked my mimes.php for docx extension:
Code:
'docx' => array('application/msword', 'application/zip', 'application/octet-stream', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'text/plain', 'application/x-zip'),

Since download_helper takes the first element in the array, replaced 'application/msword' with 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', so resulting line is:
Code:
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/octet-stream', 'application/msword', 'text/plain', 'application/x-zip'),

Now files are downloaded with correct type. Problem solved.




Theme © iAndrew 2016 - Forum software by © MyBB