473,372 Members | 1,065 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,372 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 20675
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.