Download files, content-type
Posted: Thu Feb 20, 2003 3:48 pm
Hello,
I am trying to allow users to create a text file (not using a txt extention) from a MySQL query, file is created and then I want to open the save file as dialog for them to download the file, then I unlink() the file from the directory. By using a slight twist on the manuals suggested way of doing this that I found on the PHPfaq page, I have the functionality I want, but only in IE6 and NS7 (win). If I try it with IE5.5 - win, it offers the file loaded in the window, but if I choose to open file from location, it opens the created text file, if I try to save it locally, it saves the current page open in the browser.
I looked at the download lib of the phpMyAdmin, but it's very complicated and I need to get this going ASAP. Has any of you folks ever built something like this before, or no of a place where I can find the requirments for the different browsers.
Thanks,
- D
Here is what I'm using now:
I am trying to allow users to create a text file (not using a txt extention) from a MySQL query, file is created and then I want to open the save file as dialog for them to download the file, then I unlink() the file from the directory. By using a slight twist on the manuals suggested way of doing this that I found on the PHPfaq page, I have the functionality I want, but only in IE6 and NS7 (win). If I try it with IE5.5 - win, it offers the file loaded in the window, but if I choose to open file from location, it opens the created text file, if I try to save it locally, it saves the current page open in the browser.
I looked at the download lib of the phpMyAdmin, but it's very complicated and I need to get this going ASAP. Has any of you folks ever built something like this before, or no of a place where I can find the requirments for the different browsers.
Thanks,
- D
Here is what I'm using now:
Code: Select all
$save_as = $filename . "." . $file_type;
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$save_as");
if (strpos($save_as,'\'') !== false
or strpos($save_as,'/') !== false
or strpos($save_as,':') !== false) die('Not current directory');
if (!readfile($save_as));