gpt4 book ai didi

php - 如何使用PHP使用GAE将图像上传到谷歌云存储

转载 作者:搜寻专家 更新时间:2023-10-31 21:50:04 24 4
gpt4 key购买 nike

我正在尝试使用 PHP 代码将图像上传到 Google 云存储。我尝试按照 Google 文档中提供的说明进行操作,但它不起作用。这是我的代码:

<?php
use google\appengine\api\cloud_storage\CloudStorageTools;

$options = ['gs_bucket_name' => 'myappname-178614.appspot.com'];
$upload_url = CloudStorageTools::createUploadUrl('/upload/handler', $options);
$file_name = $_FILES['uploaded_files']['name'];
$temp_name = $_FILES['uploaded_files']['tmp_name'];
move_uploaded_file($temp_name, "gs://myappname-178614.appspot.com/$file_name.jpg");
?>
<form action="<?php echo $upload_url;?>" enctype="multipart/form-data" method="post">
Files to upload: <br>
<input type="file" name="uploaded_files" size="40">
<input type="submit" value="Send">
</form>

运行代码时没有错误...有人可以帮忙吗?

最佳答案

找到解决方案:

<?php

use google\appengine\api\cloud_storage\CloudStorageTools;

$bucket = 'myapp-178614.appspot.com';
$root_path = 'gs://' . $bucket . '/';

$_url = '';
if(isset($_POST['submit'])){
if(isset($_FILES['userfile'])){
$name = $_FILES['userfile']['name'];
$file_size =$_FILES['userfile']['size'];
$file_tmp =$_FILES['userfile']['tmp_name'];
$original = $root_path .$name;
move_uploaded_file($file_tmp, $original);
$_url=CloudStorageTools::getImageServingUrl($original);
}
}

?>
<html>
<body>
<form action="test.php" method="post" enctype="multipart/form-data">
Send these files:<p/>
<input name="userfile" type="file" /><p/>
<input type="submit" name="submit" value="Send files" />
</form>
</body>
</html>
<?php

echo $_url;

?>

关于php - 如何使用PHP使用GAE将图像上传到谷歌云存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46088418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com