Browser not displaying file

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
anevins
Forum Newbie
Posts: 3
Joined: Sun Oct 31, 2010 6:13 am

Browser not displaying file

Post by anevins »

My PHP file keeps trying to save or open when i view it, even in firefox.
I'm trying to open it on a webserver and localhost but i still get the same pop-up window which asks me to either open it or save it.

The file is index.php:

Code: Select all

<?php

require_once('connectvars.php');

$dbc = mysql_connect ($server, $username, $password);
if(!$dbc){
die('Not connected : ' . mysql_error());
}

$db_selected = mysql_select_db($database, $dbc);
if (!$db_selected){
die ('Cannot use db: ' . mysql_error());
}

$query = 'SELECT * FROM maps WHERE 1';
$result = mysql_query($query);
if (!$result){
die('Invalid query ' . mysql_error());
}

//creates an array of strings to hold the liens of the KML file
$kml = array('<?xml version="1.0" encoding="UTF-8"?>');
$kml[] = '<kml xmlns="http://earth.google.com/kml/2.1">';
$kml[] = ' <Document>';
$kml[] = ' <Icon>';
$kml[] = ' <href>http://maps.google.com/mapfiles/kml/pal2/icon18.png</href';
$kml[] = ' </Icon>';
$kml[] = ' <Icon>';
$kml[] = ' <href>http://maps.google.com/mapfiles/kml/pal2/icon18.png</href';
$kml[] = ' </Icon>';

//Adds note for each row
while ($row = @mysql_fetch_assoc($result)){
$kml[] = ' <Placemark>' . $row['id'] . '">';
$kml[] = ' <city> ' . htmlentities($row['city']) . '</city>';
$kml[] = ' <Point>';
$kml[] = ' <coordinates>' . $row['lng'] . ',' . $row['lat'] . '</coordinates>';
$kml[] = ' </Point>';
$kml[] = ' <Placemark>';
}

//End of XML file
$kml[]= '</Document>';
$kml[]= '</kml>';
$kmlOutput = join("\n", $kml);
header('Content-type: application/vnd.google-earth.kml+xml');
echo $kmlOutput;
?>
Last edited by Benjamin on Sun Oct 31, 2010 4:11 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Browser not displaying file

Post by Jonah Bron »

The headers aren't setup properly. Sounds like you either didn't install PHP, or it wasn't integrated with Apache properly.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Browser not displaying file

Post by josh »

Web browsers display text/html, text/css text/javascript, etc... You are using google earth KML file. Why *wouldn't* it prompt you to save/open?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Browser not displaying file

Post by Jonah Bron »

Hehe, didn't even look at the code :oops:

If you want to be able to view your KML in the browser, change the header() method to this:

Code: Select all

header('Content-type: text/plain');
Post Reply