PHP file stream/download useability question
Posted on 2003-03-10
I've worked on a website that does a lot of file handling throughout it. There are a number of places throughout the website where I need to serve files out to someone who clicks a link. These files need to be secure and are therefore hidden off of the webserver.
Many of the website users aren't web savvy and when the file open dialog box pops up, the simply click 'open', but the files don't work. What usually happens (most of these documents are Word, excel or other MS Office docs) is the program loads, and then an error such as "This file cannot be opened" is displayed. If the user saves the file to his/her drive then runs the file, it works fine.
This is confusing the website's users to no end and I've been asked to do something about it.
Does anyone know why this does this? Is there a way to fix it?
This is my code for downloading a file:
$filename = $docinfo['filename'];
$file_path = $docinfo['path'];
$file = $file_path."/".$filename;
$len = filesize($file);
header("content-disposition: attachment; filename=$filename");
Thanks in advance!