Last active
December 28, 2015 18:59
-
-
Save dftaiwo/7547275 to your computer and use it in GitHub Desktop.
Uploading Files on Google App Engine with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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