首页 > 解决方案 > GAE 上的 PHP ZipArchive 返回只读文件系统

问题描述

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

$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 存在
文件夹可写
Can open gs://my_bucket/new_zip_file.zip
numfiles: 1
status:0
GetStatusString: No error
Closed with: false
GetStatusString:创建临时文件失败:只读文件系统

标签: phpgoogle-app-enginegoogle-cloud-storageziparchive

解决方案


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


推荐阅读