dtiu94034 2016-08-13 16:39 采纳率: 0%
浏览 474
已采纳

如何将base64转换为zip并移动到服务器

I am using JSZip for zipping some user upload file and store this zip file on a server. zip_file contains the zip file which I want to store in a server. zip_file is in base64 format so, if I stored it in PHPMyAdmin as LongText format, its could not store some zip. Is it possible to convert zip_file to zipping and move to a directory? If yes how can do it? Or How to store base64 value in PHPMyAdmin.

zip.generateAsync({type:"base64"}).then(function (content) {
   zip_file = "data:application/zip;base64," + content;
   //zip_file convert and move to /uploads folder
});
  • 写回答

1条回答 默认 最新

  • dream2891 2016-08-13 17:00
    关注

    You can set return type to blob, use XMLHttpRequest() to post Blob to php

    zip.generateAsync({type:"blob"}).then(function (content) {
       var request = new XMLHttpRequest();
       request.open("POST", "/path/to/server");
       request.send(content);
    });
    

    at php use php://input, see Beyond $_POST, $_GET and $_FILE: Working with Blob in JavaScript and PHP

    <?php
    
      // choose a filename
      $filename = "file.zip";
    
      // the Blob will be in the input stream, so we use php://input
      $input = fopen('php://input', 'rb');
      $file = fopen($filename, 'wb'); 
    
      // Note: we don't need open and stream to stream, 
      // we could've used file_get_contents and file_put_contents
      stream_copy_to_stream($input, $file);
      fclose($input);
      fclose($file);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口