0

我正在使用 JSZip 压缩一些用户上传文件并将这个 zip 文件存储在服务器上。zip_file包含我要存储在服务器中的 zip 文件。zip_file是 base64 格式,所以如果我将它作为LongText格式存储在 PHPMyAdmin 中,它就无法存储一些 zip。是否可以转换zip_file为压缩并移动到目录?如果是的话怎么办?或者如何在 PHPMyAdmin 中存储 base64 值。

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

1 回答 1

1

您可以设置返回typeblob用于XMLHttpRequest()发布Blobphp

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

在 php 使用php://input中,请参阅超越 $_POST、$_GET 和 $_FILE:在 JavaScript 和 PHP 中使用 Blob

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

?>
于 2016-08-13T17:00:50.953 回答