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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘