Class 'Google\Cloud\Storage\StorageClient' not found - php

use Google\Cloud\Storage\StorageClient;
require __DIR__ . '\vendor\autoload.php';
$storage = new StorageClient();
That as my code.Here I have installed composer on windows and getting following error:-
Fatal error: Class 'Google\Cloud\StorageClient' not found in C:\xampp\htdocs\fingertips\application\controllers\teacher.php on line 214
And even after running commands with composer to use google cloud api's, then also nothing is happening.
On cmd, when I am running this, "composer require google/cloud-storage" ,I am getting this
Using version ^1.3 for google/cloud-storage
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
I have run so many commands to fix this but didnt get anything in success.Can somebody please help what went wrong

In regards to your second question, you didn't include the actual error you're seeing.
I can see an issue with this code block though:
require __DIR__ . '\vendor\autoload.php';
$storage = new StorageClient();
$file = fopen($params['book']['tmp_name'], 'r');
$bucket = $storage->bucket('fingertips-books');
$object = $bucket->upload($params['book']['name'], [
'name' => 'test.pdf'
]);
I'm missing the actual data you want to upload. The upload method needs data to upload. This should work:
require __DIR__ . '\vendor\autoload.php';
$storage = new StorageClient();
$bucket = $storage->bucket('fingertips-books');
$object = $bucket->upload(file_get_contents($params['book']['tmp_name']), [
'name' => 'test.pdf'
]);
See the documentation for more examples of how to go about uploading a file.

Have you installed storage client? as stated here.
https://packagist.org/packages/google/cloud-storage
use
composer require google/cloud-storage

Related

Class not found after installing with composer

I followed the instructions to install this package:
https://github.com/embedly/embedly-php#installing
In my code I did:
$api = new Embedly\Embedly(array('user_agent' => 'Mozilla/5.0 (compatible; mytestapp/1.0)'));
$objs = $api->oembed('http://www.bbc.com/news/world-latin-america-37077172?ns_mchannel=social&ns_campaign=bbc_breaking&ns_source=twitter&ns_linkname=news_central');
print_r($objs);
But I get this error:
Class 'Embedly\Embedly' not found
What am I missing? Do I have to put something in the provider/alias? If so, I don't know what. I'm using Laravel 5.2.
I guess you just followed README, which was missing line for composer.
I've added that in PR.
To explain that, Composer handles all your autoloading and dependencies. To enable that explicitly, you need to include it's autoload file, where all this happens.
Just begin your index.php (or container) file with:
<?php
require_once __DIR__ . '/vendor/autoload.php';
// your code
Just add another '\' at the beginning like this:
$api = new \Embedly\Embedly(...) ;

class 'MongoDB\Cient' not found

I am using the following code to create a connection to a MongoDB server, so as to create databases and stuff but I keep getting class 'MongoDB\Cient' not found. I really need help.
<?php
$client = new MongoDB\Client('mongodb://localhost:27017');
$db = $client->reach;
$collection = $db->messages;
$collection->insertOne($record);
?>
where $record is some record.
Also, $mng = new MongoDB\Driver\Manager("mongodb://localhost:27017"); connects and I can use it to communicated with any already created db (using the command line). So, I want to ask if MongoDB\Driver\Manager can substitute MongoDB\Client?
After all the struggle, this solved the issue...
installing using composer:
$ composer require "mongodb/mongodb=^1.0.0"
OUTPUT:
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Installing mongodb/mongodb (1.0.0)
Downloading: 100%
Writing lock file
Generating autoload files
Usage:
<?php
require 'vendor/autoload.php'; // include Composer goodies
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->demo->beers;
$result = $collection->insertOne( [ 'name' => 'Hinterland', 'brewery' => 'BrewDog' ] );
echo "Inserted with Object ID '{$result->getInsertedId()}'";
?>
That fixed the issue for me. follow the link:
http://docs.php.net/manual/en/mongodb.tutorial.library.php

Installing Composer with autoload.php and use Aws\* says Class not found

I'm running my php in cli under my user.
I have installed composer and autoloader.php does exist. Under vendor folders and file have been downloaded (autoload.php aws, bin, composer, guzzlehttp, mtdowling and psr)
Now in my php code I do:
// Include the SDK using the Composer autoloader
require 'vendor/autoload.php';
use Aws\Route53\Route53Client;
use Aws\Common\Credentials\Credentials;
$credentials = new Credentials('KEY', 'SECRETKEY');
$client = Route53Client::factory(array(
'credentials' => $credentials
));
When I run the script I get: PHP Fatal error: Class 'Credentials' not found in /home/user/updatedns.php on line 15
I tried running it a sudo also (in case it needs to write to the directory) and still get this error.
Just found out that use Aws\Common\Credentials\Credentials; is now under use Aws\Credentials\Credentials;

Elastic search configuration issue with client call php

I am using elasticsearch API php to build search results. I have configured everything in my xampp server. All the libraries downloaded from composer.json. In my composer.json file contains below code
{
"require": {
"elasticsearch/elasticsearch": "~2.0"
}
}
Libraries are successfully downloaded. After that i initialize the elastic search with below code
<?php
require 'vendor/autoload.php';
$client = ClientBuilder::create()->build();
It shows fatal error like as follows
Fatal error: Class 'ClientBuilder' not found in E:\Xampp\htdocs\codeporn\elasticsearch\app\init.php on line 4
So i change the config code as,
require_once 'vendor/autoload.php';
$es = new Elasticsearch\Client([
'hosts' => ['127.0.0.1:9200']]
]);
This also shows error like
Parse error: syntax error, unexpected ']' in E:\Xampp\htdocs\codeporn\elasticsearch\app\init.php on line 10
I am following the below youtube tutorial to build the search
https://www.youtube.com/watch?v=3xb1dHLg-Lk
Please suggest what i went wrong in Elasticsearch - PHP.
My PHP Version is 5.5.9
i have initialize the clientbuilder class, now it works fine
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
you need install it with composer
composer require elasticsearch/elasticsearch

remains status code 500 in slim framework

When a install by composer:
/var/www/html/slim# php composer.phar install Loading composer
repositories with package information Installing dependencies
(including require-dev) from lock file Nothing to install or update
Generating autoload files
when i check:
tail -f /var/log/apache2/error.log
Failed opening required 'Slim\Slim.php'
(include_path='.:/usr/share/php:/usr/share/pear')
My code is:
require 'Slim\Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->get('/hoheckell/:nome)',
function($nome = null){
echo 'Hoheckell' . $nome . '<br />';
});
$app->run();
And remains the Status Code:500 Internal Server Error
Searching a bit more I changed the version that was installed, it was the last stable. God sure as it was found Slim.php file.
The documentation is weak in this part.
This code works:
require_once 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->get('/',
function($nome = null){
echo 'Hoheckell: ' . $nome;
});
$app->run();

Categories