Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Changing the content type

by carterniall (Novice)
on Jul 15, 2008 at 19:15 UTC ( #697781=perlquestion: print w/ replies, xml ) Need Help??
carterniall has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script which can print either XML or KMl depending on teh choice of the user. When teh script is run through a browser the user is given the choice of what to do with the file.

I was wondering if there would be a method of allowing them to download and save it as a .XML or .KML extension instead of a .PL extension. I want them to only see it as XML or KML as opposed to a perl script. Any clues as I am coming up stumps.

I have tried changing the content type to: "Content-type: application/vnd.google-earth.kml+xml\n\n"; which was good until they new version of Google Earth stopped that. This method did not help my problem of offering an XML version (.xml) to download though.

Any clues? Sorry if it's a bit vaige but would be more than happy to elaborate...

Niall

Comment on Changing the content type
Download Code
Re: Changing the content type
by friedo (Prior) on Jul 15, 2008 at 19:34 UTC
    To set the filename of a downloaded file, add a content-disposition header with a filename attribute. For example
    content-disposition: attachment; filename=foo.kml
      Many thanks, adding the content-disposition worked a charm

      I had a bt of a thick moment as you have to remove the

      print "Content-type: application/vnd.google-earth.kml+xml\n\n";
      line for the content disposition to work.

      Many thanks monks

Re: Changing the content type
by psini (Deacon) on Jul 15, 2008 at 19:39 UTC

    Not sure if this is what you are looking for, but I use:

    print $q->header(-type=>'text/xml'); print $q->header(-attachment=>'filename.xml');

    where $q is a CGI object, to make the browser see a file filename.xml of type text/xml when opening my cgi script.

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

      FAIL. That prints two sets of headers.

      $ perl -MCGI -e 'my $q = CGI->new(); print $q->header(-type=>"text/xml +"); print $q->header(-attachment=>"filename.xml");' Content-Type: text/xml; charset=ISO-8859-1 Content-Disposition: attachment; filename="filename.xml" Content-Type: text/html; charset=ISO-8859-1

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Thank you for the correction. I'll check tomorrow when I'm at office if (a) the above code is really the one I use and (b) if our script shows the same problem!

        It is absolutely possible that we have put in production a program that duplicates the content-type and that Firefox accepts it without a warning using the first and discarding the second one.

        Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://697781]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2014-12-25 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls