问题描述
我目前正在使用一个php应用程序将图像上传到Google云存储平台,然而,与我的本地服务器不同,我很难找出如何完成这项工作。
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.
这正是我想要做的:
- 将图片的路径写入我的Google云端SQL
- 实际上传图片至Google云端存储平台 我的网站
任何人都可以指出正确的方向吗?
Can anyone point in the right direction?
谢谢!
推荐答案
表格上的GAE - 上传图片从表格通过PHP谷歌云存储给予您的文件夹权限设置...
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);
调用图像以在您的网站上显示的脚本是典型的mysqli或pdo方法来获取文件名,你可以显示图片...
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>"/>
这篇关于如何将图像从PHP表单上传到Google云端存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!