Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Firefox tries to download php files

  • 16 பதிலளிப்புகள்
  • 1 இந்த பிரச்சனை உள்ளது
  • 5 views
  • Last reply by Roland Tanglao

Hi

I'm running a MAMP PRO installation on my OS X 11.6 which works perfectly (Apache & MYSQL). All of a sudden Firefox asks for download when browising to a .php file on my localhost. Could anybody give me a hint on why this happesn?

Thanks, Tom

Hi I'm running a MAMP PRO installation on my OS X 11.6 which works perfectly (Apache & MYSQL). All of a sudden Firefox asks for download when browising to a .php file on my localhost. Could anybody give me a hint on why this happesn? Thanks, Tom

All Replies (16)

Hi, unfortunately can not give you a idea as to why.

Please go to Options --> General --> Applications and check for php in the list. If it is in the list Click on it and tell it what you want to do.

Firefox has never processed PHP code natively. You need to have server software running locally that processes the PHP code and that sends the resulting file as text/plain instead of application/x-httpd-php.

Please see if anything on this page helps : https://stackoverflow.com/questions/27565664/prompted-to-download-when-opening-php-files-in-firefox

A web server needs to process the PHP code and send the resulting file as text/html to the browser. Firefox doesn't process PHP code and can only work with HTML, so if Firefox wants shows the "open with" dialog and wants to download then this means that the files are not send with the correct content-type.

Hi Tom, do you mean an address like this:

http://localhost/index.php

Could you check the content-type the server is sending. One way is to open the Network Monitor in the lower part of a tab -- either

  • "3-bar" menu button > Web Developer > Network
  • (menu bar) Tools > Web Developer > Network
  • (Mac) Command+option/alt+e

-- then try to load the page in the top part of the tab. Cancel the download dialog, click the request in the Network Monitor, and inspect the Response headers in the pane on the right for the Content-Type.

What you want to see is text/html but probably it's something that Firefox doesn't think can be displayed in a tab.

If Content-Type is normal, look for a Content-Disposition header ("attachment" forces a download).

You need something like this to make the server process the file and send the file with the correct content-type. Otherwise the server may send it as application/x-httpd-php and that makes Firefox present the open with dialog.

<?php header('Content-Type: text/html; charset=utf-8'); header('Vary: Accept'); ?>

jscher2000 said

What you want to see is text/html but probably it's something that Firefox doesn't think can be displayed in a tab.

That's exactly what I see - nevertheless FF opens the dialog box... This happens on many localhost sites on my computer, but not on all of them. Some installations on localhost run fine (couple of joomla and WP sites and phpbb blogs - that's why I know that apache and mysql are running on my machine).

Any other ideas on what might cause this behaviour? Thanks for all your help, Tom

ok, I deleted the mimeTypes.rfd file - no success. I also reset the plugin.disable_full_page_plugin_for_types without any success. FF is still trying to download the php file...

So other

http://localhost/myapp/index.php

files work normally, but the one

http://localhost/myapp/bad.php

does not. And you have ruled out the obvious issues:

  • loaded using http:// not file://
  • Content-Type header received by Firefox is text/html (or text/plain)
  • Content-Disposition header is not present or if it is present does not contain "attachment"

It doesn't make sense for Firefox not to render text/html content retrieved via http:// in a tab if not instructed to treat it as a download.


Does Safari show the file in a tab?

Could you test in Firefox's Safe Mode? In its Safe Mode, Firefox temporarily deactivates extensions, hardware acceleration, and some other advanced features to help you assess whether these are causing the problem.

If Firefox is not running: Hold down the option/alt key when starting Firefox. (On Windows, hold down the Shift key instead of the option/alt key.)

If Firefox is running: You can restart Firefox in Safe Mode using either:

  • "3-bar" menu button > "?" Help button > Restart with Add-ons Disabled
  • (menu bar) Help menu > Restart with Add-ons Disabled

and OK the restart.

Both scenarios: A small dialog should appear. Click "Start in Safe Mode" (not Refresh).

Any improvement?

that's correct: some localhost applications start well, other don't (there's no coincidence between WP, Joomla or phpbb - one phpbb site starts, the other one not).

I've tried in FF safe mode. No success. Safari as well downloads the php file and does not show it in a tab. So it might be related to MAMP PRO?

Can you post the HTTP response headers as shown in the Network Monitor?

Note that current Firefox releases use handlers.json and no longer use mimeTypes.rdf, so you can try to remove handlers.json instead.

cor-el மூலமாக திருத்தப்பட்டது

ok, removed handlers.json - no effect. Here are response headers from Network Monitor:

Accept-Ranges bytes Connection Keep-Alive Content-Type application/x-httpd-php Date Thu, 20 Sep 2018 20:03:08 GMT ETag "66857e0-20c6-5764702a9eec0" Keep-Alive timeout=5, max=100 Last-Modified Thu, 20 Sep 2018 05:44:03 GMT Server Apache Transfer-Encoding chunked Request headers (472 B) Accept text/html,application/xhtml+xm…plication/xml;q=0.9,*/*;q=0.8 Accept-Encoding gzip, deflate Accept-Language de-CH,en-US;q=0.7,en;q=0.3 Cache-Control no-cache Connection keep-alive Cookie gaShowOptOut=false; _ga=GA1.1.277754305.1536175087 DNT 1 Host localhost Pragma no-cache Upgrade-Insecure-Requests 1 User-Agent Mozilla/5.0 (Macintosh; Intel …) Gecko/20100101 Firefox/62.0

You can see: Content-Type: application/x-httpd-php

This means that a server isn't processing the PHP code and this means that Firefox offers to download the file like I wrote above. This will only work with Firefox if the server processes the PHP code and sends a text/html content-type.

Do you have this PHP directive at the start of the file to instruct the server to process the file?

<?php header('Content-Type: text/html; charset=utf-8'); header('Vary: Accept'); ?>

There's a file somewhere in Apache where you associate each file extension with a content type. I am surprised php is not already handled. As a fallback you can put it in a .htaccess file at the root of the application.

ok, the PHP directive is present at the start of the file to instruct the server to process the file. But of no success.

How do I define this to the .htaccess file? (sorry, but I never had to deal with those things... ;-)

Thanks for all your help!

Do you currently have any .htaccess files in the directories of the problem web pages?

Hi tcgass

This is a Firefox user support forum; it is not a web developer forum for debugging your PHP web application. I appreciate the awesome advice that jscher2000, cor-el and many others have tried on this forum to help you but it's not really this forum's area of expertise!

Please use the appropriate channel (tag it PHP on stackoverflow.com for example?) as per:

https://support.mozilla.org/en-US/kb/where-go-developer-support

Cheers!

...Roland