Question

I implemented a basic mvc framework in php. The problem is that when I want to create a dynamic kml file not open, because the file at the start of blank spaces are generated. If I do it from any file (not the framework), it works correctly.

Link :localhost/Radio/index/asset

Controller : indexController.php method : asset()

code:

public function asset() {

    $dom = new DOMDocument('1.0', 'UTF-8');



    $kmlOutput = $dom->saveXML();
    $kmlOutput = trim($kmlOutput);              
    header('Content-type: application/vnd.google-earth.kml+xml');
    header('Content-disposition: attachment; filename="myfilename.kml"');
    echo  $kmlOutput;

}

error in Google Earth :

error

kml generate:

enter image description here

Thanks in advance.

Was it helpful?

Solution

Blanks at the beginning of the output are often caused by newlines behind the closing php tag.

<?php¶
¶
// Some code here¶
¶
?>¶
¶

Anything outside of <?php ?> as directly seen as output. Therefor, you should never use the closing tag in library files.

To quote Zend Framework:

For files that contain only PHP code, the closing tag ("?>") is never permitted. It is not required by PHP, and omitting it´ prevents the accidental injection of trailing white space into the response.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top