Skip to content

Instantly share code, notes, and snippets.

@dftaiwo
Last active December 28, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dftaiwo/7547275 to your computer and use it in GitHub Desktop.
Save dftaiwo/7547275 to your computer and use it in GitHub Desktop.
Uploading Files on Google App Engine with PHP
<?php
/**
* For uploads to the Cloud Storage using PHP, The form must be submitted first to Google.
*
* All information on that form is sent to you.
*
*
*
*/
require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;
$options = [ 'gs_bucket_name' => '__YOUR_BUCKET_NAME__' ];
$gooCs = new CloudStorageTools();
/*
__YOUR_UPLOAD_URL - when the user submits the form, this is where the file should be posted.
It is usually the value of the action attribute in your form tag .
$gaeFormUploadUrl this is the url you should put in the action tag.
*/
$gaeFormUploadUrl = $gooCs->createUploadUrl('__YOUR_UPLOAD_URL', $options);
/**
* Just process your $_POST and $_FILES data as you would,except for move_uploaded_file.
* The $_FILES['upload_field']['tmp_name'] actually holds your absolute, permanent path to the file in your Bucket.
* You should save that information in your database or datastore for future reference
*
*/
/*
If you need to get the URL to an image you uploaded, use the following method.
Use the size parameter if you want the image resized for you
*/
$gooCs->getImageServingUrl($gsUrl, array('size' => 400));
/**
* Check out https://developers.google.com/appengine/docs/php/refdocs/files/api.cloud_storage.CloudStorageTools#\google\appengine\api\cloud_storage\CloudStorageTools for more
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment