473,395 Members | 1,974 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.

Prompt to "Save As" No Matter What The File Type

What I want is to have a link to a file (it could be a .zip, .exe, .jpg,
..txt or even .html) and when the user clicks on it they are prompted with
the Save As box, as opposed to it opening in the browser.
I think I need to do something like:

$fp = fopen($filetooutput, "rb");
$thefile = fread($fp, filesize($thefiletooutput));
header("Content-type: ???/???"); not sure what to put instead of the ???
echo $thefile;

If anyone can help that would be much appreciated
Richie
Jul 17 '05 #1
5 20676
Richie a écrit le 27/01/2004 :
What I want is to have a link to a file (it could be a .zip, .exe, .jpg,
.txt or even .html) and when the user clicks on it they are prompted with
the Save As box, as opposed to it opening in the browser.
I think I need to do something like:

$fp = fopen($filetooutput, "rb");
$thefile = fread($fp, filesize($thefiletooutput));
header("Content-type: ???/???"); not sure what to put instead of the ???
echo $thefile;

If anyone can help that would be much appreciated
Richie


Don't mess up the Content-type header, consider using :
<?php
header("Content-disposition: attachment;
filename=my_name_of_the_file");
?>
But look at Google for know issues on some browser versions.
Jul 17 '05 #2
Richie wrote:

What I want is to have a link to a file (it could be a .zip, .exe, .jpg,
.txt or even .html) and when the user clicks on it they are prompted with
the Save As box, as opposed to it opening in the browser.
I think I need to do something like:

$fp = fopen($filetooutput, "rb");
$thefile = fread($fp, filesize($thefiletooutput));
header("Content-type: ???/???"); not sure what to put instead of the ???
echo $thefile;


Google for content-disposition header. Set it to "attachment", I think. That
doesn't work on some browsers, though.

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #3

"Jedi121" <je*********@free.fr.Removethis> wrote in message
news:me********************************@free.fr.Re movethis...
Richie a écrit le 27/01/2004 :
What I want is to have a link to a file (it could be a .zip, .exe, .jpg,
.txt or even .html) and when the user clicks on it they are prompted with the Save As box, as opposed to it opening in the browser.
I think I need to do something like:

$fp = fopen($filetooutput, "rb");
$thefile = fread($fp, filesize($thefiletooutput));
header("Content-type: ???/???"); not sure what to put instead of the ???
echo $thefile;

If anyone can help that would be much appreciated
Richie


Don't mess up the Content-type header, consider using :
<?php
header("Content-disposition: attachment;
filename=my_name_of_the_file");
?>
But look at Google for know issues on some browser versions.


That worked great, thanks.
Hopefully on the few browsers that it doesn't work on, it'll just open the
file in the browser as normal

Richie
Jul 17 '05 #4
Richie wrote:
What I want
Perhaps unwittingly, you've made known the root of the perceived
problem already: what you want and what someone else wants aren't
necessarily one and the same.
is to have a link to a file (it could be a .zip, .exe, .jpg, .txt or
even .html) and when the user clicks on it they are prompted with the
Save As box, as opposed to it opening in the browser.
(a) What "Save As box"? My browser didn't come with one. ;-)

(b) What makes you think that you know how I ought to deal with
files?

(c) Which piece of software would you have me open an HTML file with,
if not my browser?
header("Content-type: ???/???"); not sure what to put instead of the ???


The file's media type perchance? Here's the authoritative registry
for Internet media types:

ftp://ftp.isi.edu/in-notes/iana/assi...s/media-types/

And you'll see that Content-Disposition -- a non-HTTP/1.1 header,
defined in the experimental RFC1806 -- has been put forward as a
suggestion in other followups, which have rightly warned against
sending illegitimate Content-Type headers. If your wish is to convey
presentational information, this is the logical way.

But sending this header, with a disposition type of attachment, does
*not* guarantee that a client will ask the user what she wants done
with the file; not being part of the HTTP/1.1 draft standard,
conforming applications aren't obliged to act upon Content-
Disposition headers. I reckon RFC1806's intention is *not*, without
a smidgen of a doubt, to provide servers with the mechanism to
"force" particular actions on clients. Is that not your inference
too?

--
Jock
Jul 17 '05 #5
>doesn't work on some browsers, though.

It should not work in IE 4.x browsers and below.
____________________________________
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
DigitallySmooth Inc. | Quick Site Studio
Jul 17 '05 #6

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

Similar topics

8
by: dave | last post by:
Hi there I'm trying to force save as dialogue using this code in download.asp..but when it runs it prompts for download.asp to save or open. code snippet (from aspfaq.com) ...
4
by: Richard | last post by:
Hi I'm new to ASP/Web programming so any help would be appreciated... Situation: On my web page I would like to present a link {or button} that would allow the user to download a large file. ...
3
by: B-Dog | last post by:
I'm checking some files to see if the filenames are in a certain format and if not I want to pull up a dialog box that gives me a save as with the file that is in question. I have all the files in...
5
by: Matt S. | last post by:
I have been using C# 2005 Express to make class libraries for use in another software program. Each version of this software has a different .NET API, so maintaining multiple solutions of the same...
60
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.