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

File Download NOT open

I have a php page that reads files links from a Database.
This works well, but when we click on the link the file starts to open.

Is there anyway to force the file to SAVE not open ??

thanks

Sep 13 '06 #1
6 1803
je***********@yahoo.com wrote:
I have a php page that reads files links from a Database.
This works well, but when we click on the link the file starts to open.

Is there anyway to force the file to SAVE not open ??

thanks
Yes,

You should send the right headers so the browser knows it should safe the
file.
Here is a piece of code that seems to work for me.

---------------------------
$file_name = 'myexport.csv';

// Create headers for save-as dialog
header('Content-Type: text/comma-separated-values');
//IE need specific header...
if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))
{
header('Content-Disposition: inline; filename="'.$file_name.'"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
} else {
header('Content-Disposition: attachment; filename="'.$file_name.'"');
header('Pragma: no-cache');
}
---------------------------

That example was just for a csv file.
You need another content-type for other kind of files.

Maybe reading up here will help a bit:
http://nl2.php.net/manual/en/functio...ntent-type.php

Good luck!

Regards,
Erwin Moller
Sep 13 '06 #2
je***********@yahoo.com wrote:
I have a php page that reads files links from a Database.
This works well, but when we click on the link the file starts to open.

Is there anyway to force the file to SAVE not open ??

thanks
Jerry,

You can't force them to save it. That's up to the browser settings the
user has entered, and you can't override those (which is a good thing).

As Erwin indicated, if you are actually generating the files in PHP
code, you need to set the headers appropriately. But if all you're
doing is pointing to an existing file on the server, the server itself
should set the appropriate header.

They can always right click on the link and select "Save Link..." (exact
wording depends on the browser). I'd recommend you add a note to the
effect "To save the file, click your right mouse button on the link and
select Save".

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 13 '06 #3
Jerry Stuckle wrote:
je***********@yahoo.com wrote:
I have a php page that reads files links from a Database.
This works well, but when we click on the link the file starts to
open.

Is there anyway to force the file to SAVE not open ??

[snip]

They can always right click on the link and select "Save Link..."
(exact wording depends on the browser). I'd recommend you add a note
to the effect "To save the file, click your right mouse button on the
link and select Save".
Something that's gonna be a slight problem for people using a Mac.

--
Kim André Akerĝ
- ki******@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Sep 13 '06 #4
Kim André Akerĝ wrote:
Jerry Stuckle wrote:

>>je***********@yahoo.com wrote:
>>>I have a php page that reads files links from a Database.
This works well, but when we click on the link the file starts to
open.

Is there anyway to force the file to SAVE not open ??

[snip]

They can always right click on the link and select "Save Link..."
(exact wording depends on the browser). I'd recommend you add a note
to the effect "To save the file, click your right mouse button on the
link and select Save".


Something that's gonna be a slight problem for people using a Mac.
Isn't there an equivalent operation for Macs?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 13 '06 #5
je***********@yahoo.com wrote:
I have a php page that reads files links from a Database.
This works well, but when we click on the link the file starts to open.

Is there anyway to force the file to SAVE not open ??

thanks

Here's what I use for a PDF file. Create a script and "present" the file
through it.

<?php

header('Content-Description: File Transfer');
header('Content-Type: application/pdf'); // change this to your mime type
header('Content-Length: ' . filesize($file));

// to download
header('Content-Disposition: attachment; filename=' . basename($file));

// to open in browser
// header('Content-Disposition: inline; filename=' . basename($file));

readfile($file);
?>

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
Sep 13 '06 #6
Jerry Stuckle wrote:
Kim André Akerĝ wrote:
Jerry Stuckle wrote:

je***********@yahoo.com wrote:
>
I have a php page that reads files links from a Database.
This works well, but when we click on the link the file starts
to open.

Is there anyway to force the file to SAVE not open ??
>
[snip]
>
They can always right click on the link and select "Save Link..."
(exact wording depends on the browser). I'd recommend you add a
note to the effect "To save the file, click your right mouse
button on the link and select Save".
Something that's gonna be a slight problem for people using a Mac.

Isn't there an equivalent operation for Macs?
Ctrl+click, I think. (Hold the CTRL key and click)

--
Kim André Akerĝ
- ki******@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Sep 13 '06 #7

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

Similar topics

2
by: John Spiegel | last post by:
Hi all, How does one allow a user to download a file WITH selecting where it should be downloaded to on their machine? Also, when using the WebClient.Download method, will the destination path...
7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
0
by: Rhys666 | last post by:
Basically I have a link that opens my download page and the querystring identifies the type of 'template' Excel spreadsheet has asked to download. The download page reads the querystring,...
2
by: Ken Varn | last post by:
I have an ASP.NET page that incorporates the following code on a button press. private void DownloadTag_Command(object sender, CommandEventArgs e) { FileStream fs; String Filename; Filename...
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
1
by: sunita | last post by:
Hiii I open a file download dialog from a modal dialog...From the file download dialog i can either save or open the file.. Is there a way i can let the modal dialog that opens the file download...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
7
by: lawrence k | last post by:
I've got a music studio for a client. Their whole studio is run with Macintosh computers. Macintosh computers allow file names to have open white spaces, such as "animal hospital.mp3". I have a...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
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...
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...
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:
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
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.