2016-12-26 48 views
1

我正在尝试使用PHP从Google App Engine上传图片。图像正在上传到适当的云存储桶路径,但由于它包含错误,因此无法访问。当我上传800kb大小的图像时,它显示12个字节到云存储。我也尝试上传1kb大小的文件,尽管它显示了12个字节的大小。我没有得到确切的问题。 这里是我上传图片到谷歌云存储的代码:图片未正确上传到使用GAE的Google Cloud存储php

$file_name = $_FILES['filetoUpload']['name']; 
$temp_name = $_FILES['filetoUpload']['tmp_name']; 
$type = $_FILES['filetoUpload']['type']; 
$options = array('gs' => array('entity' => 'allUsers', 'role' => 'READER', 'acl' => 'public-read', 'Content-Type' => $type, 'contentEncoding' => 'ANSI')); 
$context = stream_context_create($options); 
$publicFileText = date('ymdhis'); 
$fileName = "gs://<bucket-name>/" . $file_name; 

file_put_contents($fileName, $publicFileText, 0, $context); 
$publicUrl = CloudStorageTools::getPublicUrl($fileName, TRUE); 

回答

1

您没有上传图片文件。你只是上传$publicFileText,这是一个字符串。

+0

我需要在$ publicFileText传递什么?我已经传递$ fileName作为第一个参数。 –

+0

尝试:'file_put_contents($ fileName,$ _FILES ['filetoUpload'],0,$ context);' – GAEfan

+0

我试过你的解决方案..但是,仍然没有工作.. –