浏览器要求我下载 php 文件

2021-12-25 00:00:00 file download browser php

我是网络编程的新手,仍在学习新东西.

I am a new guy in web programming who still learning new stuff.

我正在创建一个包含一个 INPUT 的 Web 表单.我将 HTML 文件中的表单连接到 php 文件.我正在使用我最近在 MacBook 上安装的本地主机 MAMP.

I am creating a web form that consist of one INPUT. I connected the form in the HTML file to the php file. I am using a localhost MAMP that I recently installed on my MacBook.

问题: 当我在网页上打开 HTML 文件并在输入框中输入内容并点击提交时,浏览器要求我下载 php 文件而不是处理它.

The Problem : When I open the HTML file on a webpage and type something on the input box and hit submit, the browser ask me to download the php file rather processing it.

我认为问题与 mysql 或 apache 无关,因为当我运行 MAMP 时,它会在 apache 和 mysql 旁边给我绿色标志.

I don’t think the problem is related to mysql or apache since when I run the MAMP it give me green signs next to the apache and mysql.

有谁知道我如何解决这个问题并让 php 文件打开并将输入传输到数据库?

Do anyone know how I can fix this problem and the let the php file open and transfer inputs to the database?

推荐答案

您需要确保 Apache 已被告知 .php 文件应被视为 PHP 脚本.这意味着以下之一:

You'll want to make sure that Apache has been told that .php files should be treated as PHP scripts. That means one of the following:

LoadModule php5_module        modules/libphp5.so    # on windows, this'd be a .dll instead
AddHandler php5-script php 

和/或

AddType application/x-httpd-php php

在您的 httpd.conf 文件中.

in your httpd.conf file.

相关文章