嗨,当我运行下面的脚本时,我得到一个奇怪的错误。它将返回此错误消息
Parse error: syntax error, unexpected 'new' (T_NEW) in /home/apipetfindr/public_html/sys/v1/google_cloud_storeage_upload.php on line 9我想知道为什么我的这部分代码不能工作:
private $storage = new StorageClient我知道我需要将我尝试过的新函数调用为public,而不是private,但没有成功。如果有人能给我指出正确的方向,那就太好了。
<?php
# Includes the autoloader for libraries installed with composer
require '../vendor/autoload.php';
use Google\Cloud\Storage\StorageClient;
class googleupload{
private $storage = new StorageClient([
'projectId' => 'xxxxxxxxxx'
]);
private $bucket = $storage->bucket('BUCKET_NAME');
// Upload a file to the bucket.
//$bucket->upload(
// fopen('/data/file.txt', 'r')
//);
public function uploads($_FILE, $uid){
$obj = new Google_Service_Storage_StorageObject();
$obj->setName($file_name);
$resp = $storage->objects->insert(
"bucketname",
$obj,
array('name' => $file_name, 'data' => file_get_contents("300mb-file.zip"), 'uploadType' => 'media')
);
}
}
/*
// Download and store an object from the bucket locally.
$object = $bucket->object('file_backup.txt');
$object->downloadToFile('/data/file_backup.txt');
*/
?>https://stackoverflow.com/questions/44427803
复制相似问题