【问题标题】:How to run php script on Google App Engine?如何在 Google App Engine 上运行 php 脚本?
【发布时间】:2021-03-05 10:10:38
【问题描述】:

我在 Google App Engine 环境中遇到了一个 php 脚本问题。

我尝试使用 ajax-call 调用 php 脚本,但成功回调总是返回未处理的 php 文件 (<?php .... ?>)

ajax 调用如下所示:

$.ajax({
        type: "POST",
        url: "/contactform-process.php",
        data: "name=" + name + "&email=" + email + "&message=" + message + "&terms=" + terms, 
        success: function(text) {
            console.log('Hello')
            if (text == "success") {
                cformSuccess();
            } else {
                cformError();
                csubmitMSG(false, text);
            }
        }
    });

我假设我必须声明 Google App Engine 环境正在正确处理 php 文件。我当前的 app.yaml:

runtime: php74

handlers:
- url: /
  static_files: static/index.html
  upload: static/index.html

- url: /de
  static_files: static/de/index.html
  upload: static/de/index.html

- url: /en
  static_files: static/en/index.html
  upload: static/de/index.html

- url: /(.*)
  static_files: static/\1
  upload: static/(.*)

- url: /(.+\.php)$
  script: auto

- url: /contactform-process.php
  script: auto

有人知道遗漏了什么,所以 php 文件会以正确的方式处理吗?

【问题讨论】:

    标签: php ajax google-app-engine


    【解决方案1】:

    /contactform-process.php 匹配的第一个处理程序是/(.*),它是一个静态文件处理程序,因此它只是按原样返回您的 PHP 文件(不执行它)。

    您希望它匹配 (.+\.php)$之前它匹配 /(.*),因此您需要在处理程序列表中切换这两个的顺序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-12
      • 2014-10-18
      • 1970-01-01
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      • 2019-05-21
      相关资源
      最近更新 更多