Why browser is trying to download my php script file?

13,028

Solution 1

If the file extension is .php and your web server correctly configured it will run it.

You specify an application/xxx content type so most browsers will force a download and use the name of your script as file name.

If you want to force a file name different from your php file name use :

header('Content-Disposition: attachment; filename=your_requested_file.kml');

Solution 2

Because your web server is not correctly configured to process PHP scripts.

Solution 3

I'm assuming that this command sends a header:

header('Content-type: application/vnd.google-earth.kml');

If you're writing a file on the server and not intending to send any response to the client, why are you sending a header to the client?

If your PHP file is just supposed to write a file on the server and do nothing else, don't send a header or indeed anything else to the client.

If that doesn't help, try rephrasing your question. You have received a wide variety of responses so far to all manner of different problems.

Solution 4

I have experienced that it happens due to some error in the .htaccess, it may seem absurd because i did not mentioned anything to see in the .htaccess. You should take a closer look in to it.

Solution 5

If the browser is trying to download the PHP source, then this means that Apache was either not configured to run the PHP interpreter and/or, if you are using a Linux, Unix, or Mac OS X operating system, Apache did not have permission to execute the PHP script.

You need to follow the instructions at Manually Configure PHP5 and Apache2 to make sure that your httpd.conf is correct.

If, in addition, you are running Apache on Linux, Unix, or Mac OS X, then you need to open a terminal, cd into the directory that contains your PHP script, and:

chmod a+x SCRIPT.php

where SCRIPT.php is the name of your PHP script.

Share:
13,028
Pavel
Author by

Pavel

Updated on June 27, 2022

Comments

  • Pavel
    Pavel almost 2 years

    Just a quick one - I wrote a php script recently that dynamically creates XML file using API DOM. So I'm using this at the beginning:

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

    And at the end it looks like this:

    $server = $_SERVER['DOCUMENT_ROOT'];
    $path_to_xml = "$server/project/file.xml"; 
    file_put_contents($path_to_xml, $dom->saveXML());
    

    It does everything I wanted but why browser is trying to download this php script instead of just run it? Please can someone help me with this. I'm pretty sure it's something easy. //-----------------------------------edited Thanks for all replies. Yes I'm sending custom headers because it's google maps kml file that I'm creating dynamically.

    header('Content-type: application/vnd.google-earth.kml');

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

    Could that be possible cause of this?