【问题标题】:how to upload a image to google cloud storage with GAE using php如何使用 php 使用 GAE 将图像上传到谷歌云存储
【发布时间】:2018-02-15 17:22:20
【问题描述】:

我正在尝试使用 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 google-app-engine google-cloud-storage


    【解决方案1】:

    找到解决办法:

    <?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;
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 2013-11-30
      • 2020-03-19
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 2015-06-13
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      相关资源
      最近更新 更多