RE: Need some help handling file downloads.

From: Date: Wed, 16 Apr 2003 10:17:53 +0000
Subject: RE: Need some help handling file downloads.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144099@lists.php.net to get a copy of this message
You can do it like this. // Get the mime type from the db withc was saved while the file was posted inn. $mime_type = db_get_mime_type($HTTP_SESSION_VARS['session_user']['username'], $fileName, $current_path); send_file_as_download($fileToDownload, $fileName, $mime_type); function send_file_as_download($filenameAndDir, $filename, $mime_type) { Global $HTTP_SESSION_VARS; // FILE_ROOT = is a magical root to the file storage. // $HTTP_SESSION_VARS['session_user']['Files'] = This user's private directory. $fileName = FILE_ROOT.'/'.$HTTP_SESSION_VARS['session_user']['Files'].$filenameAndDir; $file_size = filesize ($fileName); $file = fopen ($fileName, "r"); Header("Content-type: ".$mime_type); // Set the mime_type header("Content-Disposition: attachment; filename=".$filename); // place the file as an attachment NOT as standart out fpassthru($file); } enjo. -----Original Message----- From: Nicole Stevens [mailto:nicole@ducksfeet.com] Sent: 16. apríl 2003 00:28 To: php-general@lists.php.net Subject: Need some help handling file downloads. Hello, I am new here and if this sort of thing has been asked before, please forgive me. I'm writing a PHP application which connects users and allows for sharing of files. Users need to be able to upload files to the server and download them from a personal area and a public area. The user is logged in via a form and once logged in a cookie is set to keep track of who they are and what their current state is. The files in question can be of any type, and, are located in an area protected from the public. Files are presented in a dynamic tree-style display (in an IFRAME) now, the problem I have is when a link is clicked for one of these files, regardless of the header that I send with the appropriate mime type, internet exploder wants to save the file as PHP file. (since that is the URL, i.e., http://www.myserver.tld/gimmefile.php?dickandjane.doc) What I would like, and I dont know if this is possible, is to have my script force via headers (is this even possible?) the filename to be saved, and the mime-type for the file. I have thought of various methods of copying, temporarily, the file wanted to a temp directory which is accessible and doing a redirect to that file, but, I dont want to have something which cleans the garbage on occasion, and, it really breaks the security of what I want to do. I have thought about using Apache 2.0's mod_ext_filter stuff -- and wonder, also, if that would be a viable way of handling this. Any help on this is appreciated. TIA, Nicole --- Nicole Stevens - nicole@ducksfeet.com

« previous php.general (#144099) next »