【问题标题】:Where should the upload_handler.php be located?upload_handler.php 应该放在哪里?
【发布时间】:2014-01-07 20:04:47
【问题描述】:

我正在使用带有 REST API 的 PHP。我正在尝试使用 AJAX 上传文件并检索缩略图。

app.yaml

- url: /api/(.*)
  script: api/index.php 
- url: /.*
  script: index.html

Javascript:当用户选择要上传的图片时触发此函数。

onFileSelect = function($files) {

    for (var i = 0; i < $files.length; i++) {
        var upload_url = $http.get('/api/upload/new'); //Create a new upload url

        $http.uploadFile({
            url: upload_url,
            file: $files[i]
        }).success(function(pulic_url, status) {
            console.log( pulic_url ); //Print the public url of the uploaded file
        })
    }
}

但这不起作用,我得到的公共 URL 如下所示:

http://localhost:8080/_ah/upload/adfrhtbnekj...

当我发出 POST 请求时,它只会打印出 index.html 文件。这意味着它没有找到我的upload_handler.php

我的 upload_handler.php 应该放在哪里?

【问题讨论】:

    标签: php google-app-engine google-cloud-datastore


    【解决方案1】:

    上传处理程序必须在 app.yaml 文件中作为脚本引用。这意味着一个人应该能够像其他任何脚本一样调用脚本(即发出 post/get 请求,因为上传代理会像往常一样将 [发出请求] 重定向到您的应用程序)。您当前的文件仅处理 api/ 和 .* 到 index.html,这意味着当访问 /upload_handler.php 时,它将被重定向到 index.html。

    也许你想要类似下面的东西

    - url: /upload_handler.php
      script: upload_handler.php
    

    # next release /(.+\.php)$ will work as well.
    - url: /(.+\.php$) 
      script: \1
    

    【讨论】:

      猜你喜欢
      • 2012-02-17
      • 2018-11-20
      • 1970-01-01
      • 1970-01-01
      • 2017-11-06
      • 2012-07-18
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多