views:

33

answers:

1

I have a PHP file called dynamicxml.php that runs a bunch of code, draws data from a database and creates an XML file. When I right-click and save the link for dynamicxml.php?var=test I need the dialog box to select xml as the default file type and rename the file to var.xml:

header("Content-type: text/xml");
echo '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<blah><blah_blah>'.$_GET['var'].'</blah></blah>';

When clicking the link it loads the xml file in the browser. Saving that page saves it as var.xml. But right clicking and saving it saves it as dynamicxml.php and as a php file type.

Should I manipulate things with htaccess or are there other alternatives?

A: 

you shouldn't try to do that because browsers work differently saving through "save as..". for example chrome and opera would save your file as .htm(probably). i see two possible ways to fix the situation(and i wouldn't do either of them):

  • set apache to process xml as php. AddType text/xml php

  • create a rewrite rule to redirect everything from *.xml in some directory to dynamicxml.php

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.xml$ - [NC,L]
    RewriteRule ^.xml$ dynamicxml.php [NC,L]
    
kgb