【问题标题】:App Engine Could not guess mimetype for PHP filesApp Engine 无法猜测 PHP 文件的 mimetype
【发布时间】:2014-04-26 16:32:39
【问题描述】:

Google App Engine、PHP、Mimetype、app.yaml、static_dir、脚本、static_files

当我部署我的网站时,PHP 文件导致错误消息:

无法猜测的 mimetype

这是appl.yaml配置文件:

application: applicationname
version: 1
runtime: php
api_version: 1
threadsafe: true

handlers:

- url: /
  script: index.php

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

- url: /Client_Pages
  static_dir: Client_Pages

导致错误的文件未加载到已部署的网站中。相同的文件可以在我的计算机上从Google App Engine Launcher 完美运行。

根目录下的index.php文件不报错,在部署的网站中运行。

似乎我部署的网站将加载PHP 文件 静态html 文件但不能同时加载?我在同一个Client_Pages 文件夹中有PHPHTML 文件。我想知道这是否会导致问题,但我找不到任何说明我不能将它们放在同一个文件夹中的文档。

我尝试在app.yaml 文件中显式引用PHP 文件,这会导致PHP 文件运行,但HTML 文件不会加载。

application: yardsalesuperhighway
version: 1
runtime: php
api_version: 1
threadsafe: true

handlers:

- url: /Client_Pages/Offered_Menu.php
  script: Client_Pages/Offered_Menu.php

- url: /Client_Pages/InputForm.php
  script: Client_Pages/InputForm.php

- url: /Client_Pages/WantedPage.php
  script: Client_Pages/WantedPage.php

- url: /Client_Pages
  static_dir: Client_Pages

【问题讨论】:

    标签: php google-app-engine mime-types app.yaml


    【解决方案1】:

    如果没有特定指令,您的应用程序无法访问存储在 static_dir 中的文件。

    来自文档 -

    应用程序可读

    可选。默认情况下,在静态文件处理程序中声明的文件是 作为静态数据上传并仅提供给最终用户,他们不能 被应用程序读取。如果此字段设置为 true,则文件为 也作为代码数据上传,以便您的应用程序可以读取它们。

    我不确定 app.yaml 中的处理程序是否可以与静态目录重叠。这不是我测试过的东西,如果不可能,我不会感到惊讶。应用程序代码被上传到 appengine 基础架构中的不同服务中。

    【讨论】:

    • 过去我使用过:- url: /Client_Pages static_dir: Client_Pages 没有任何其他规范,App Engine 提供了该目录中的所有文件。但那是我刚刚使用所有 html 文件的时候。
    • 没错,它会起作用。但是现在你正试图让它从同一个静态目录中执行 php 代码,我不相信这是可能的。最多可以,使用该指令允许 php 代码读取静态目录中的这些文件,但我不相信您的主要处理程序可以位于那里。
    【解决方案2】:

    不确定帖子是否仍然打开。我似乎遇到了类似的问题,这对我有用。我所做的是在我保存 php 文件的目录下添加 application_readable: truemime_type: text/html。所以也许你的app.yaml 应该是这样的:

    application: yardsalesuperhighway
    version: 1
    runtime: php
    api_version: 1
    threadsafe: true
    
    handlers:
    
    - url: /Client_Pages/Offered_Menu.php
      script: Client_Pages/Offered_Menu.php
    
    - url: /Client_Pages/InputForm.php
      script: Client_Pages/InputForm.php
    
    - url: /Client_Pages/WantedPage.php
      script: Client_Pages/WantedPage.php
    
    - url: /Client_Pages
      application_readable: true # allow for php scripts in the dir to be executable by the application (as specified in the documentation provided by Tim)
      mime_type: text/html # assuming the php scripts will be echoing something, have what the echo as html (I got the mime types from http://www.iana.org/assignments/media-types/media-types.xhtml)
      static_dir: Client_Pages
    

    我的代码可以使用它,它甚至可以使用与 php 脚本能够加载的同一目录中的 HTML 文件。

    【讨论】:

      【解决方案3】:

      不要使用 static_dir,而是考虑使用 static_files 仅上传您希望为静态的文件:

      handlers:
      
      - url: /Client_Pages/(.*\.php)
        script: Client_Pages/\1
      
      - url: /Client_Pages/(.*\.html)
        static_files: Client_Pages/\1
        upload: Client_Pages/.*\.html
      
      - url: /
        script: index.php
      

      【讨论】:

        猜你喜欢
        • 2013-12-23
        • 1970-01-01
        • 2017-07-21
        • 2018-06-25
        • 2013-11-25
        • 1970-01-01
        • 1970-01-01
        • 2014-12-10
        • 1970-01-01
        相关资源
        最近更新 更多