【问题标题】:How to convert an image to base64 in GAE php如何在 GAE php 中将图像转换为 base64
【发布时间】:2015-03-26 11:02:51
【问题描述】:

因为 file_open_contents() 在 GAE php 中被禁用。 任何转换图像文件(例如 png / jpg)并在 dataurl 中显示图像以隐藏文件名和路径的有效方法

【问题讨论】:

  • 您应该能够在 GAE 上对本地文件和 GCS 文件进行 file_open_contents。否则, base64_encode(file_get_contents('gs:///')) 在任何情况下都应该工作。

标签: php html image google-app-engine base64


【解决方案1】:

让我们试试这个:

HTML:

<input type="file" id="fileToUpload" name="fileToUpload" multiple="multiple">

Javascript:

 $("#fileToUpload").change(function(event) {

          $.each(event.target.files, function(index, file) {
              var reader = new FileReader();
              reader.onload = function(event) {  
              object = {};
              object.filename = file.name;
              object.data = event.target.result;
              files.push(object);
              datasrc = event.target.result;

                var inlineImgD = "<img src="+datasrc+">";
              };  
            reader.readAsDataURL(file);
          });

        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 1970-01-01
    • 2020-03-24
    • 2013-11-07
    • 1970-01-01
    • 2020-03-22
    • 1970-01-01
    相关资源
    最近更新 更多