Firebase存储和从PHP上传 [英] firebase storage and upload from php

查看:52
本文介绍了Firebase存储和从PHP上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP应用程序,因此我需要将图像上传到Google firebase存储.我见过可读写实时数据库的代码片段,但找不到任何从php上传到 firebase存储的代码.

I have a php application and from this i need upload images to google firebase storage. I had seen snippets that write to and read from realtime database but couldnt find any code that upload from php to firebase storage.

任何帮助将不胜感激.

Tismon Varghese

Tismon Varghese

推荐答案

我们建议使用Google API客户端PHP库,因为Firebase存储由Google Cloud Storage支持.但是,Firebase Storage并未为前端代码提供PHP客户端.

We recommend using the Google API Client PHP library for this, as Firebase Storage is backed by Google Cloud Storage. Firebase Storage doesn't provide a PHP client for front end code though.

来自 GCS PHP示例代码:

// composer autoloading
require_once __DIR__ . '/vendor/autoload.php';

// grab the first argument
if (empty($argv[1])) {
    die("usage: php listBuckets [project_id]\n");
}

$projectId = $argv[1];

// Authenticate your API Client
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);

$storage = new Google_Service_Storage($client);

/**
 * Google Cloud Storage API request to retrieve the list of buckets in your project.
 */
$buckets = $storage->buckets->listBuckets($projectId);

foreach ($buckets['items'] as $bucket) {
    printf("%s\n", $bucket->getName());
}

这篇关于Firebase存储和从PHP上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆