我有一个php脚本,用于存储来自放置请求的图像。脚本托管在主机怪物上
这是我的脚本
<?php
$path = 'test.png';
$put = fopen("php://input", "r");
$fp = fopen($path, "w");
while ($data = fread($put, 1024))
fwrite($fp, $data);
fclose($fp);
fclose($put);
echo 'done';
?>
我的脚本运行良好。现在我已经将此脚本移植到谷歌应用程序引擎,现在它存储无效图像。这是应用引擎脚本
<?php
$path = 'gs://my-bucket/test.png';
$options = ['gs' => ['Content-Type' => 'image/jpeg' , 'acl'=>'public-read']];
$ctx = stream_context_create($options);
$put = fopen("php://input", "r");
$fp = fopen($path, "w",false,$ctx);
while ($data = fread($put, 1024))
fwrite($fp, $data);
fclose($fp);
fclose($put);
echo 'done';
?>
使用无效内容创建文件。任何人都可以帮助/指出我做错了什么吗?
我尝试了相同的脚本,它对我来说工作正常,可能是您因为图像的大小而面临问题,因为它是生成 memcache 密钥的 PHP 库中的问题。Memcache 无法生成长度超过 250 字节的密钥。现在该错误已修复。在下面找到我尝试过的代码片段。它和你的一样。
<?php
use google'appengine'api'cloud_storage'CloudStorageTools;
use google'appengine'api'log'LogService;
$object_url = 'gs://my-bucket/test1.png';
$options = stream_context_create( ['gs' => ['acl' => 'public-read',
'Content-Type' => 'image/jpg']] );
$my_file = fopen($object_url, 'w', false, $options);
$put = fopen("image.jpg", "r");
while ($data = fread($put, 1024))
fwrite($my_file, $data);
fclose($my_file);
fclose($put);
echo 'done';
?>