473,396 Members | 1,768 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,396 software developers and data experts.

Headers and "save as" dialog box.

I have the following code which executes successfully to call the browsers
"save as" box...

//Screensavers
if ($FileType == 'scr')
{
// We'll be outputting a screensaver
header('Content-type: application/octet-stream');
// It will be called test.scr
header('Content-Disposition: attachment; filename="test.scr"');
// The location of the file
readfile('http://'.$FileURL);
}

The information for file locations etc is pulled from a database. What I
would like to do however is to be able to pull the filename from the
database and insert it as the filename, ie:

header('Content-Disposition: attachment; filename="$Name"');

But when I try to execute this, the "save as" box asks to save the file
$Name, and if I change the line to:

header('Content-Disposition: attachment; filename=$Name');

It then prompts to save the php code that is currently running.

Is there any way to insert the actual name of the file you are trying to
"save" rather than a generic name.

I've also tried writing:

echo "header('Content-Disposition: attachment; filename=\"$Name\"');";

But I get similar results.

Thanks for any help.

Dariusz
Jul 17 '05 #1
4 16313
On Wed, 31 Mar 2004 14:22:24 +0000, Dariusz wrote:
I have the following code which executes successfully to call the browsers
"save as" box...

//Screensavers
if ($FileType == 'scr')
{
// We'll be outputting a screensaver
header('Content-type: application/octet-stream');
// It will be called test.scr
header('Content-Disposition: attachment; filename="test.scr"');
// The location of the file
readfile('http://'.$FileURL);
}

The information for file locations etc is pulled from a database. What I
would like to do however is to be able to pull the filename from the
database and insert it as the filename, ie:

header('Content-Disposition: attachment; filename="$Name"');

But when I try to execute this, the "save as" box asks to save the file
$Name, and if I change the line to:

header('Content-Disposition: attachment; filename=$Name');

It then prompts to save the php code that is currently running.

Is there any way to insert the actual name of the file you are trying to
"save" rather than a generic name.

I've also tried writing:

echo "header('Content-Disposition: attachment; filename=\"$Name\"');";

But I get similar results.

Simple fix Dariusz =)

The ' ' quotes you have inside the header() call are constant quotes, this
means that $foo is _literally_ $foo rather than the _contents_ of $foo.
This is what you're seeing and why you're seeing it. Try:
header("Content-Disposition: attachment; filename=$Name");

or

header('Content-Disposition: attachment; filename=' . $Name);
The echo statement will do nothing useful for you.. just FWIW =)

Hope this helps.

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #2
Dariusz wrote:
...
The information for file locations etc is pulled from a database. What I
would like to do however is to be able to pull the filename from the
database and insert it as the filename, ie:

header('Content-Disposition: attachment; filename="$Name"');
Read the strings reference
http://www.php.net/manual/en/language.types.string.php

taking particular attention to what is and is not interpolated.

$name = 'Pedro';
$name2 = 'my name is ' . $name; // my name is Pedro
$name3 = 'my name is $name'; // my name is $name
$name4 = "my name is $name"; // my name is Pedro
$name5 = 'my name is "$name"'; // my name is "$name"
$name6 = "my name is '$name'"; // my name is 'Pedro'
But when I try to execute this, the "save as" box asks to save the file
$Name, and if I change the line to:

header('Content-Disposition: attachment; filename=$Name');


try

header('Content-Disposition: attachment; filename="' . $Name . '"');

which will output something like
Content-Disposition: attachment; filename="test.scr"
No garanties this will work as you want on all browsers though :)
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #3
In article <pa****************************@bubbleboy.digiserv .net>, "Ian.H" <ia*@WINDOZEdigiserv.net> wrote:
The ' ' quotes you have inside the header() call are constant quotes, this
means that $foo is _literally_ $foo rather than the _contents_ of $foo.
This is what you're seeing and why you're seeing it. Try:
header("Content-Disposition: attachment; filename=$Name");

or

header('Content-Disposition: attachment; filename=' . $Name);
The echo statement will do nothing useful for you.. just FWIW =)

Hope this helps.


Thanks Ian, this worked perfectly.

I didn't spot the problem as I have not worked with the headers before, so
I thought that the quote marks had to be the way I showed them in the
example (I got them off some site showing examples of the use of the
headers).

Dariusz
Jul 17 '05 #4
In article <c4*************@ID-203069.news.uni-berlin.de>, Pedro Graca <he****@hotpop.com> wrote:
taking particular attention to what is and is not interpolated.

$name = 'Pedro';
$name2 = 'my name is ' . $name; // my name is Pedro
$name3 = 'my name is $name'; // my name is $name
$name4 = "my name is $name"; // my name is Pedro
$name5 = 'my name is "$name"'; // my name is "$name"
$name6 = "my name is '$name'"; // my name is 'Pedro'
But when I try to execute this, the "save as" box asks to save the file
$Name, and if I change the line to:

header('Content-Disposition: attachment; filename=$Name');


try

header('Content-Disposition: attachment; filename="' . $Name . '"');

which will output something like
Content-Disposition: attachment; filename="test.scr"
No garanties this will work as you want on all browsers though :)


Thanks for the information Pedro. I was confused as it's the first time
working with the headers, and the example I found was not clear at all (on
the use of quote marks). The changes now work.

Thanks.

Dariusz
Jul 17 '05 #5

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

Similar topics

5
by: W.Guerlich | last post by:
I've got a Java servlet that delivers large database resultsets transformed to Excel with the HSSF library. In some cases it takes more than 15 minutes before transformation is done and content can...
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. ...
0
by: Dune | last post by:
Hi there, I have an aspx page that allows users to enter several parameters using drop downs and text boxes. The users then press a button that produces an extract based on the parameters they...
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...
1
by: Tomas Martinez | last post by:
Hi, In my web I have a proccess of download reports which on first step generates a PDF, then flushes the buffer (the generated file) and finally deletes this file from server. Ok, the problem...
1
by: deerchao | last post by:
I used these codes to provide a default "Save As" filename for browsers: Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName); Response.ContentType =...
1
by: sainathparuchuri | last post by:
As a project requirement we need to convert word documents to tiff images. We have been using Microsoft Office Document Image Writer (MODI) for this puspose and doing absolutely well. But now this...
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...
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
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
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
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
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.