Page 1 of 1

PHP Download problem

Posted: Thu Jul 01, 2010 4:33 am
by Tot
I am having issue downloading documents from my php page. When download a word document it opens it in raw format in the browser?

I'm guessing this is an issue with header types but I'm also unsure if this is a security problem over https too? I think it’s trying to download it via a php page.

This is my header code -

Code: Select all

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' .filesize ($Path) );
header('Content-Type: '.$mime_type);	
header('Content-Disposition: attachment; filename="'.$result->fileOriginalName.'"');
readfile(JPATH_BASE.'/uploadfile/documentFile/'.$result->fileName.'');
header("Connection: close");|
I am a php newbie please help.

Many thanks in advance.

Re: PHP Download problem

Posted: Thu Jul 01, 2010 8:52 am
by Jade
Don't you need this header too?

Code: Select all

header("Content-Type: application/vnd.ms-word");  

Re: PHP Download problem

Posted: Thu Jul 01, 2010 10:22 am
by Tot
Yes, although its already included within "$mime_type" above. Which determines which type is required. Thanks for your help though.

Re: PHP Download problem

Posted: Fri Jul 02, 2010 5:25 am
by Tot
I've now fixed the problem. The header code was not being called correctly, it’s now resolved my problem and works perfectly.

Re: PHP Download problem

Posted: Fri Jul 02, 2010 8:48 am
by Jade
Can you post your corrected code so it's available for future reference? Thanks!