473,395 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need help with Content-Disposition Content-Type

Arg
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
code.

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

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

//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
echo"
<script language=\"JavaScript\">
location.href=\"dl.php?fn=".$fn."\";
</script>";
?>

//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 1725

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
4
by: Phil | last post by:
k, here is my issue.. I have BLOB data in SQL that needs to be grabbed and made into a TIF file and placed on the client (could be in temp internet dir). The reason we need it in TIF format is...
8
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
5
by: HotRod | last post by:
I am new to this so please go easy. We currently have some students doing some work on some web based tracking documents for us. They are currently using VB .net to develop what we requested....
10
by: L. R. Du Broff | last post by:
I own a small business. Need to track a few hundred pieces of rental equipment that can be in any of a few dozen locations. I'm an old-time C language programmer (UNIX environment). If the only...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.