PHP Download problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tot
Forum Newbie
Posts: 3
Joined: Thu Jul 01, 2010 4:25 am

PHP Download problem

Post 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.
Last edited by Benjamin on Thu Jul 01, 2010 4:51 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: PHP Download problem

Post by Jade »

Don't you need this header too?

Code: Select all

header("Content-Type: application/vnd.ms-word");  
Tot
Forum Newbie
Posts: 3
Joined: Thu Jul 01, 2010 4:25 am

Re: PHP Download problem

Post by Tot »

Yes, although its already included within "$mime_type" above. Which determines which type is required. Thanks for your help though.
Tot
Forum Newbie
Posts: 3
Joined: Thu Jul 01, 2010 4:25 am

Re: PHP Download problem

Post 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.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: PHP Download problem

Post by Jade »

Can you post your corrected code so it's available for future reference? Thanks!
Post Reply