Skip to content Skip to sidebar Skip to footer

How To Convert Base64 To Zip And Move To Server

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 form

Solution 1:

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

zip.generateAsync({type:"blob"}).then(function (content) {
   var request = newXMLHttpRequest();
   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);

?>

Post a Comment for "How To Convert Base64 To Zip And Move To Server"