【问题标题】:PHP ZipArchive on GAE returns Read-only File SystemGAE 上的 PHP ZipArchive 返回只读文件系统
【发布时间】:2019-05-19 23:09:27
【问题描述】:

我一直在尝试使用 Google App Engine 和 PHP 的 ZipArchive 压缩存储桶中的一个文件,然后将该压缩文件存储在存储桶中。我基本上一直在向它添加错误检查,并且已经深入到只读文件系统消息。存储桶和应用程序在同一个项目中。不知道从这里去哪里。有任何想法吗?下面是我的测试代码和结果。

$zip = new ZipArchive();
$filename = "gs://my_bucket/new_zip_file.zip";
$toadd = 'gs://my_bucket/MakeaZip.txt';

if (file_exists($toadd)) {
    echo "The file $toadd exists<br>";
} else {
    echo "The file $toadd does not exist<br>";
}

if (is_writable('gs://my_bucket')) {
    echo 'Folder is writable<br>';
} else {
    echo 'Folder not writable<br>';
}

if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
    echo 'Can not open '.$filename.'<br>';
} else {
    echo 'Can open '.$filename.'<br>';
}

$content = file_get_contents($toadd);
$zip->addFromString(pathinfo ( $toadd, PATHINFO_BASENAME), $content);

echo "numfiles: " . $zip->numFiles . '<br>';
echo "status:" . $zip->status . '<br>';
echo 'GetStatusString: '.$zip->getStatusString() . '<br>';
$ret = $zip->close();
echo 'Closed with: ' . ($ret ? "true" : "false") . '<br>';
echo 'GetStatusString: '.$zip->getStatusString() . '<br>';

以上代码的结果是:

文件 gs://my_bucket/MakeaZip.txt 存在
文件夹可写
可以打开 gs://my_bucket/new_zip_file.zip
数字文件:1
状态:0
GetStatusString:没有错误
关闭:假
GetStatusString:创建临时文件失败:只读文件系统

【问题讨论】:

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


    【解决方案1】:

    Google Cloud Storage 中没有支持压缩的官方功能。对此有一个开放的功能请求,但是,目前没有实施它的计划。您可以找到here 功能请求并关注任何更新,您还可以查看this 以了解一些用户提出的使用 PHP 的解决方法。

    【讨论】:

      猜你喜欢
      • 2020-07-10
      • 2012-08-23
      • 2016-08-04
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      • 2018-04-10
      • 2010-12-22
      相关资源
      最近更新 更多