【问题标题】:move_uploaded_file() could not move file to Google Storage on Google App Engine (php 7.2)move_uploaded_file() 无法将文件移动到 Google App Engine 上的 Google Storage (php 7.2)
【发布时间】:2018-12-24 06:30:55
【问题描述】:
$filename = generate_filename($type, $id);
$filepath = "gs://$bucket.appspot.com/uploadedfiles/$filename";
error_log("trying to move ".$_FILES['image']['tmp_name']." to ".$filepath);
if (file_exists($_FILES['image']['tmp_name'])) {
    if (move_uploaded_file($_FILES['image']['tmp_name'], $filepath)) {
        // ...
    } else {
        error_log("could not move the uploaded file");
    }
}

这是我在日志中看到的:

试图将 /tmp/php69rSck 移动到 gs://my-project.appspot.com/uploadedfiles/sale-image-3-1545631667.1964.jpg

无法移动上传的文件

如何确定失败的原因?

【问题讨论】:

  • 文件大小是多少? move_uploaded_file() 报告的错误消息是什么?App Engine 的文件大小限制为 32 MB。
  • @JohnHanley 我尝试了几张不同的图片,所有图片都低于 100k。
  • 您调用的 Google API 返回的错误信息是什么?这会给你一个真正的线索。

标签: php google-app-engine google-cloud-platform google-cloud-storage php-7.2


【解决方案1】:

我发现了问题所在。我忘记启用gs:// 流包装器:​​

require_once 'vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;

$storage = new StorageClient();
$storage->registerStreamWrapper();

【讨论】:

    猜你喜欢
    • 2015-07-07
    • 2020-04-04
    • 2014-11-22
    • 1970-01-01
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 2013-01-26
    相关资源
    最近更新 更多