Santiago
Santiago

Reputation: 1745

Google Drive REST API Documentation working directory

I'm following this instructions of QuickStart Google Drive REST API in PHP but in the part where say "working directory" I need to move the quickstart.php and client_secret.json but I don't know where is the working directory.

I'm using Windows Server 2012 R2 with Apache and PHP 5.6 and only I need to put these files in that working directory, not working in htdocs in Apache folder.

Upvotes: 0

Views: 115

Answers (1)

camelsWriteInCamelCase
camelsWriteInCamelCase

Reputation: 1665

Working directory can be any web accessible directory in htdocs folder, for example my_google_disk. But don't forget to restrict access to the client_secret.json file. You can do it in 3 ways:

1) The most simple will be to save client_secret.json contents in PHP string variable inside your script, for example:

$clientSecretData = '{...}' // client_secret.json data here

Then you just need to decode the contents of the variable to get JSON string as array as follows:

 $clientSecretData = json_decode($clientSecretData, true);

2) You can save it in any web accessible directory (htdocs/my_google_disk, for example), but then you need to create .htaccess file in that directory and save there special directives for access control:

<Files "client_secret.json">
Order Allow,Deny
Deny from all
</Files>

After that, try to access this file by URL http://example.com/my_google_disk/client_secret.json (example.com = your domain name) and you'll see a 404 Forbidden error.

You'll be able to get data from that file in htdocs/my_google_disk/quickstart.php as follows:

$clientSecretData = file_get_contents('client_secret.json');

3) Save it inside directory, that is located a level higher than the htdocs directory, for example, C:\apache\private_files. private_files here must be not accessible by URL. Set this directory to include path in your script. Then you'll be able to get data from that file in your script from htdocs/my_google_disk directory as follows:

$clientSecretData = file_get_contents('../../private_files/client_secret.json');

Upvotes: 1

Related Questions