javascript - Get zip file from non-public folder (php) -
i have zip file in non-public folder of web server. want make file not accessible public, looking use php readfile read zip file , create file object zip file in javascript. not sure if best way appreciate suggestion.
how use returned data construct file object?
here php code (getzipfile.php):
<?php $filename = "abc.zip"; $filepath = "/path/to/zip/"; // http headers zip downloads header("pragma: public"); header("expires: 0"); header("cache-control: must-revalidate, post-check=0, pre-check=0"); header("cache-control: public"); header("content-description: file transfer"); header("content-type: application/octet-stream"); header("content-disposition: attachment; filename=\"".$filename."\""); header("content-transfer-encoding: binary"); header("content-length: ".filesize($filepath.$filename)); ob_end_flush(); $buffer = readfile($filepath . $filename); echo $buffer; ?>
and here javascript code
$.ajax({ url: 'getzipfile.php', error: function(e) { console.log(e); }, datatype: 'text', success: function(data) { console.log(data); var parts = [ new blob([data], {type: 'application/zip'}), new uint16array([33]) ]; var f = new file(parts, "myzip.zip"); }, type: 'get' });
one thing noticed size of th original zip file 2302 bytes, when print data.length in success function, data length 2287. should same?
where $buffer comes ? additionnaly don't seem sending file, should add :
echo readfile($filepath . $filename);
you add control check if file exists, beyond question's scope.
Comments
Post a Comment