2011-02-11 6 views
0

私のKMLジェネレータの次のステップに問題があります。私はそれを持っているので、日付を選択すると、ジェネレータに日付が送信され、ダウンロードされるKMLが作成されます。それはファイルを作成しますが、ダウンロードされるファイルはgenerator.phpと呼ばれます。それにはすべてのKML情報が含まれていますが、それは私が望んでいたものではありません。ですから、私は、ファイルを.kmlにするための小さな助けやチュートリアルが必要です。ここに私のコードは、これまでのところです:index.phpのPHP KMLジェネレータ

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> 
     <title>TDM KML Generator</title> 
     <script type="text/javascript" src="calendarDateInput.js"></script> 
    </head> 
    <body> 
    <form action="generator.php" method="post"> 
     <script type="text/javascript">DateInput('orderdate', true, 'YYMMDD')</script> 
     <input name="submit" type="submit" value="get KML" /> 
    </form> 

    </body> 
</html> 

generator.php

<?php 
      if($_SERVER['REQUEST_METHOD'] == 'POST') 
      { 
       $date = $_POST['orderdate']; 
       $file = fopen("http://www.xxxxxxxxxxxxxxxxxxx/".$date."xxxxxxxxx.csv", "r"); 
       $content = fgetcsv($file, 1000, ","); 
       $dom = new DOMDocument('1.0', 'UTF-8'); 

       // Creates the root KML element and appends it to the root document. 
       $node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml'); 
       $parNode = $dom->appendChild($node); 

       // Creates a KML Document element and append it to the KML element. 
       $dnode = $dom->createElement('Document'); 
       $docNode = $parNode->appendChild($dnode); 

       // Creates the two Style elements, one for restaurant and one for bar, and append the elements to the Document element. 
       $restStyleNode = $dom->createElement('Style'); 
       $restStyleNode->setAttribute('id', 'restaurantStyle'); 
       $restIconstyleNode = $dom->createElement('IconStyle'); 
       $restIconstyleNode->setAttribute('id', 'restaurantIcon'); 
       $restIconNode = $dom->createElement('Icon'); 
       $restHref = $dom->createElement('href', 'http://maps.google.com/mapfiles/kml/pal2/icon63.png'); 
       $restIconNode->appendChild($restHref); 
       $restIconstyleNode->appendChild($restIconNode); 
       $restStyleNode->appendChild($restIconstyleNode); 
       $docNode->appendChild($restStyleNode); 

       $barStyleNode = $dom->createElement('Style'); 
       $barStyleNode->setAttribute('id', 'barStyle'); 
       $barIconstyleNode = $dom->createElement('IconStyle'); 
       $barIconstyleNode->setAttribute('id', 'barIcon'); 
       $barIconNode = $dom->createElement('Icon'); 
       $barHref = $dom->createElement('href', 'http://maps.google.com/mapfiles/kml/pal2/icon27.png'); 
       $barIconNode->appendChild($barHref); 
       $barIconstyleNode->appendChild($barIconNode); 
       $barStyleNode->appendChild($barIconstyleNode); 
       $docNode->appendChild($barStyleNode); 
       $id = 1; 
       while (($content = fgetcsv($file, 1000, ",")) !== FALSE) { 
/******************************************************************************************* 
        Values of content 
        (ignore)****content[0] = Time*******(ignore) 
           content[1] = Size 
        (ignore)****content[2] = Location***(ignore) 
           content[3] = City 
           content[4] = State 
           content[5] = Lat 
           content[6] = Long 
           content[7] = Comments 
*******************************************************************************************/ 
        if ($content !== false) { 

         $node = $dom->createElement('Placemark'); 
         $placeNode = $docNode->appendChild($node); 

         // Creates an id attribute and assign it the value of id column. 
         $placeNode->setAttribute('id', 'placemark' . $id); 

         // Create name, and description elements and assigns them the values of the name and address columns from the results. 
         $descNode = $dom->createElement('description', $content[7]); 
         $placeNode->appendChild($descNode); 
         $styleUrl = $dom->createElement('styleUrl', '#barStyle'); 
         $placeNode->appendChild($styleUrl); 

         // Creates a Point element. 
         $pointNode = $dom->createElement('Point'); 
         $placeNode->appendChild($pointNode); 

         // Creates a coordinates element and gives it the value of the lng and lat columns from the results. 
         $coorStr = $content[6] . ',' . $content[5]; 
         $coorNode = $dom->createElement('coordinates', $coorStr); 
         $pointNode->appendChild($coorNode); 
        } 
        $id = $id + 1; 
       }  
       $kmlOutput = $dom->saveXML(); 
       header('Content-type: application/vnd.google-earth.kml+xml'); 
       echo $kmlOutput; 
       fclose($file);  
      } 
     ?> 

答えて

2

headerのためのPHPマニュアルでの実施例1を見てください:

したい場合ユーザーは に送信するデータを保存するように促されます 生成されたPDFファイルなど »Content-Dispositio nヘッダーを入力して、 に推奨ファイル名を指定し、ブラウザに保存ダイアログを表示させます。

<?php // We'll be outputting a PDF 
header('Content-type: application/pdf'); 

// It will be called downloaded.pdf 
header('Content-Disposition: attachment; filename="downloaded.pdf"'); 
// The PDF source is in original.pdf 
readfile('original.pdf'); ?> 
+0

これを使用するとファイルが作成されますが、そこには何もありません。 – shinjuo

+0

申し訳ありませんこれは間違っていましたが、私は間違って使いました。助けてくれてありがとう – shinjuo