470,815 Members | 1,084 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Need help with Content-Disposition Content-Type

I posted this to alt.comp.lang.php last week and got no response so I am
reposting it here today...

I am trying to use the following script to allow users to download files
with some of the file name stripped off. This script is for use on my
company intranet and only has to work with Internet Explorer 6. When the
files are uploaded (through another PHP script) they are prefixed with a
timestamp to prevent files with duplicate filenames from overwriting each
other and to maintain a document history. I am actually storing the file
information in a database, but that part works and is not relevant to this
question so I am putting the filename right into the link to simplify the

Try 1:
File to be retrevied = filename.pdf
Actual filename on server = files/12345~filename.pdf

// script name dl.php
$nfn=explode('~',$fn); // seperate actual filename from timestamp (12345~)
$typ=explode('.',$fn); // get filetype from filename
header('Content-type: application/'.$typ[$ct]);
header('Content-Disposition: attachment; filename="'.$nfn[1].'"');

//Line to call for file from other webpage
<a href="dl.php?fn=12345~filename.pdf">Get file</a>

The above script works fine if the user clicks on the link to start the
download, but, if they should happen to drag the link to their desktop to
create a shortcut they get the file, only it is named dl.php. If they
rename the file to the proper extension it works fine but I don't want them
to have to rename the file.

Try 2:
If I use the following to redirect the page to dl.php it works from the link
or the shortcut, but then it leaves a blank orphaned browser window behind
in both cases.

// script name=dl1.php
<script language=\"JavaScript\">

//Line to call for file from other script
<a href="dl1.php?fn=12345~filename.php" target=newwin>Get file</a>

Notice I added target=newwin in this link because without it the window with
the link on it goes blank due to the redirect.

Any help with this would be appreciated.

Jul 17 '05 #1
0 1605

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sofia | last post: by
4 posts views Thread by Phil | last post: by
2 posts views Thread by Michael R. Pierotti | last post: by
5 posts views Thread by HotRod | last post: by
10 posts views Thread by L. R. Du Broff | last post: by
reply views Thread by U S Contractors Offering Service A Non-profit | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.