473,893 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('Conten t-Disposition: attachment; filename=\"$Nam e\"');";

But I get similar results.

Thanks for any help.

Dariusz
Jul 17 '05 #1
4 16365
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('Conten t-Disposition: attachment; filename=\"$Nam e\"');";

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.dig iserv.net>, "Ian.H" <ia*@WINDOZEdig iserv.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
2609
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 be delivered to the browser. I want to show the "Save As" dialog as early as possible so the user knows he's not lost and forgotten. I already tried to send the response headers immediately after receiving the request including content...
4
5577
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. When the user clicks to start the download I would like to display the "Save As" dialog, allow the user to name a place to save the file, and then show the download progress bar while the file downloads Question: How do I make a windows "Save...
0
2983
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 entered. When this button is pressed and extract is prduced and IE's standard Open/Save dialog should popup so they can navigate to the directory to save the extract in, or if they want, they can choose to open and view the extract without saving it. ...
3
2562
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 a certain directory and if it doesn't meet my criteria then I want to do a "save as" to a different location. How can I do that. I can't seem to get the save as dialog to grab the filename of the file in question and ask for a place to save it....
1
1516
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 is that using it with Windows 2000, when the "Save as..." dialog box appears and a user clicks "Open" button, the dialog reappears and for opening the file it must be clicked again. In fact the first dialog box shows a message more or less like...
1
4441
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 = "application/octet-stream"; But if there are space chars in the file name, FireFox would split the recommed file name, and use the first part only. For example, if fileName=="aaa bbb.watever", then the "Save As" dialog will take "aaa"
1
3896
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 process need to be automated. Whenever a document is converted to tiff MODI pops up a "Save as" dialog box which asks the path to save the converted tiff file. Now is there a way this "Save as" dialog box can be suppressed and all the files be...
0
9985
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10839
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10927
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9646
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5858
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6066
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3289
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.