简体   繁体   English

Google云端存储上传了不可读的文件名(php)

[英]Google Cloud Storage uploaded unreadable filesnames (php)

After some problems i could finally upload files with google app engine to my bucket, but now the name of the uploaded file is unreadable, like a temp name, encrypted or something, like this: 经过一些问题后,我终于可以使用google app引擎将文件上传到我的存储桶中,但是现在上传的文件名不可读,例如临时名称,加密文件或类似内容:

L2FwcGhvc3RpbmdfcHJvZC9ibG9icy9BRW5CMlVvQWFjdkRYbWhtY1dPRGc2ZjlkVzRUU0lOV0FFMThWZnAxbUl1MzFVUndLSWdYVTBvdHhyYXl4UWdNOElXWklvX2hkQjdfaHYxbWNvc0dlSEtSQ184enJCU3M4QS5PTW5KWVBiTWdWZTJGdmQ4 L2FwcGhvc3RpbmdfcHJvZC9ibG9icy9BRW5CMlVvQWFjdkRYbWhtY1dPRGc2ZjlkVzRUU0lOV0FFMThWZnAxbUl1MzFVUndLSWdYVTBvdHhyYXl4UWdNOElXWklvX2hkQjdfaHYxbWNvc0dlSEtSQ184enJCU3M4QS5PTW5KWVBiTWdWZTJGdmQ4

How can i give the name that i want to an uploaded file??? 如何给上载的文件命名???

I'm using the same code as the one given in the google developers documentation, like this: 我使用的是与Google开发人员文档中给出的代码相同的代码,如下所示:

require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;

$options = [ 'gs_bucket_name' => 'my_bucket' ];
$upload_url = CloudStorageTools::createUploadUrl('/upload_handler.php', $options);


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

Does anybody know if Amazon's S3 is easier and more standard friendly? 有人知道亚马逊的S3是否更轻松,更标准友好吗? Also if it's posible to comunicate with GAP, I think i read that it is posible, but now i'm not sure about anything, too late and my brain is burnt :( 另外,如果可以与GAP交流,我想我读到它是可以的,但是现在我不确定任何事情,为时已晚,我的大脑烧坏了:(

Thanks in advance!! 提前致谢!!

I made it work, it was easy, i just missunderstood something... 我做到了,这很容易,我只是误解了一些东西...

It must be done in upload_handler.php, is obvious but...xD. 它必须在upload_handler.php中完成,很明显,但是... xD。 And as Mars says with move_uploaded_file, or with rename. 正如火星所说的那样,使用move_uploaded_file或重命名。 Something like this (maybe is usefull for someone): 这样的事情(可能对某人有用):

$gs_tmpName = $_FILES["myfile"]['tmp_name'];
$ext = strrchr($gs_name, ".");
$desired_name = "<desired_name>$ext";
$desired_name = mb_convert_encoding($desired_name, "UTF-8", "AUTO");
$desired_name = urlencode($desired_name);
$options = array('gs'=>array('acl'=>'public-read','Content-Type' => $_FILES['myfile']['type']));
$ctx = stream_context_create($options);
rename($gs_tmpName, "gs://<bucket_name>/".$desired_name, $ctx);
$publicUrl = CloudStorageTools::getPublicUrl('gs://<bucket_name>/'.$desired_name , true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM