【问题标题】:Google Cloud Storage file upload error in Google App Engine standard running PHP 7运行 PHP 7 的 Google App Engine 标准中的 Google Cloud Storage 文件上传错误
【发布时间】:2019-11-04 00:32:56
【问题描述】:

我有一个使用 Google App Engine 标准环境构建的 PHP 7 应用程序,我希望能够上传文件并将它们存储在 Google Cloud Storage 中。我正在使用Blueimp jQuery File Upload 插件来处理文件的上传。

我遇到了一些错误。有一条错误消息说failed to open stream: Read-only file system。这些是错误消息:

Warning: move_uploaded_file(/srv/c/server/php/files/cats.png): failed to open stream: Read-only file system in /srv/c/server/php/UploadHandler.php on line 1152

Warning: move_uploaded_file(): Unable to move '/tmp/phpsKIIYL' to '/srv/c/server/php/files/cats.png' in /srv/c/server/php/UploadHandler.php on line 1152

Warning: filesize(): stat failed for /srv/c/server/php/files/cats.png in /srv/c/server/php/UploadHandler.php on line 322

Warning: unlink(/srv/c/server/php/files/cats.png): Read-only file system in /srv/c/server/php/UploadHandler.php on line 1171

Warning: Cannot modify header information - headers already sent by (output started at /srv/c/server/php/UploadHandler.php:1152) in /srv/c/server/php/UploadHandler.php on line 1201

{"files":[{"name":"cats.png","size":false,"type":"image\/png","error":"File upload aborted","deleteUrl":"https:\/\/myproject.appspot.com\/c\/server\/php\/index.php?file=cats.png","deleteType":"DELETE"}]}

谁能解释一下我做错了什么?

【问题讨论】:

  • 您使用什么样的逻辑将文件保存到 GCS?
  • 你需要发布你的代码

标签: google-app-engine google-cloud-storage blueimp


【解决方案1】:

这是将对象上传到您的存储桶 php 的示例代码:

use Google\Cloud\Storage\StorageClient;

//create a bucket 
$storage = new StorageClient();
$bucket = $storage->bucket('my_bucket');


//upload file
$source = 'path_to_file'
$file = fopen($source, 'r');
$objectName = 'my_file'
$object = $bucket->upload($file, [
    'name' => $objectName
]);

【讨论】:

  • 谢谢玛丽安,但我已经有一个桶,所以不需要创建一个新的。
猜你喜欢
  • 2015-07-07
  • 1970-01-01
  • 1970-01-01
  • 2018-01-15
  • 2020-04-04
  • 2014-11-22
  • 1970-01-01
  • 1970-01-01
  • 2013-11-02
相关资源
最近更新 更多