问题
I'm currently utilizing a php app to upload images to the Google cloud storage platform, however, unlike on my local server, I am having tremendous trouble figuring out how to make this work.
Here is exactly what I am trying to do:
- Write the Path of the image to my Google cloud SQL
- Actually upload the image to the Google cloud storage platform
- write a script calling on the image, from the saved SQL path, to then post to my site
Can anyone point in the right direction?
Thanks!
回答1:
Something like this worked for me with the form on GAE - upload photo from Form via php to google cloud storage given your folder permission are set...
// get image from Form
$gs_name = $_FILES["uploaded_files"]["tmp_name"];
$fileType = $_FILES["uploaded_files"]["type"];
$fileSize = $_FILES["uploaded_files"]["size"];
$fileErrorMsg = $_FILES["uploaded_files"]["error"];
$fileExt = pathinfo($_FILES['uploaded_files']['name'], PATHINFO_EXTENSION);
// change name if you want
$fileName = 'foo.jpg';
// put to cloud storage
$image = file_get_contents($gs_name);
$options = [ "gs" => [ "Content-Type" => "image/jpeg"]];
$ctx = stream_context_create($options);
file_put_contents("gs://<bucketname>/".$fileName, $gs_name, 0, $ctx);
// or move
$moveResult = move_uploaded_file($gs_name, 'gs://<bucketname>/'.$fileName);
The script to call the image to show on your site is typical mysqli or pdo method to get filename, and you can show the image with...
<img src="https://storage.googleapis.com/<bucketname>/<filename>"/>
来源:https://stackoverflow.com/questions/22205432/how-do-i-upload-images-to-the-google-cloud-storage-from-php-form