Force file download with php using header()

carpinteyrotvm

New Member
I want the user to be able to download some files I have on my server, but when I try to use any of the many examples of this around the internet nothing seems to work for me. I've tried code like this: \[code\]<?phpheader('Content-Description: File Transfer');header('Content-Type: image/png');header('Content-Disposition: attachment; filename=Image.png');header('Content-Transfer-Encoding: binary');header('Expires: 0');header('Cache-Control: must-revalidate, post-check=0, pre-check=0');header('Pragma: public');header('Content-Length: ' . filesize("Image.png"));ob_clean();flush();readfile("Image.png");exit;?>\[/code\]I've even tried to use the most basic example I could find, like this: \[code\]<?phpheader('Content-type: image/png');header('Content-Disposition: attachment; filename="Image.png"');readfile('Image.png');?>\[/code\]When I've tested this I have removed all the other code I have and used an empty file with just this code to remove any faults created by external sources.When I look in the console the file gets sent with the right headers i.e\[code\]'Content-Disposition: attachment; filename=Image.png'\[/code\]But the save dialog isn't displayed.I've also tried with inline instead of attachment in the content disposition header but that didn't make a difference either, I've tested this in Firefox 8.0.1 Chrome 15.0.874.121 and Safari 5.1.1I'm grateful for any helpMattias
 
Top