【问题标题】:Append write not working with google storage附加写入不适用于谷歌存储
【发布时间】:2018-03-05 10:57:46
【问题描述】:

我正在尝试通过托管在 google 应用引擎上的 php 脚本将 android 应用程序的日志附加到 google 存储中的文件中。

PHP 脚本

<?php
  header("Access-Control-Allow-Origin: *");
  $file_path = 'gs://s3674204-storage/logs.txt';


  if ( 0 == filesize( $file_path) || file_exists($file_path) == false ){
        $handle = fopen($file_path, 'w') or die('Cannot open file:  '.$file_path);
        fwrite($handle, "Label,x,y,z".PHP_EOL);
        fclose($handle);
  }


  $final = $_POST['result'];
  $final = json_decode( $final, true );
  $label = array_keys($final);
  $coords = $final[$label[0]];

  $data = $label[0].",".$coords['x'].",".$coords['y'].",".$coords['z'];

  $myfile = file_put_contents($file_path,$data.PHP_EOL , FILE_APPEND | LOCK_EX);

 ?>

第一次,正在创建文件,但它无法追加写入同一个文件。

file_put_contents 返回 false

代码在 xampp 服务器上运行良好。谷歌存储出了什么问题?

【问题讨论】:

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


    【解决方案1】:

    Objects in Google Cloud Storage are immutable,这意味着您不能附加到它们或就地编辑它们。您必须用新内容完全覆盖文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 2014-01-19
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-22
      相关资源
      最近更新 更多