zipfile

How to zip a folder and download it using php?

*爱你&永不变心* 提交于 2019-11-29 00:43:02
I have folder named "data". This "data" folder contains a file "filecontent.txt" and another folder named "Files". The "Files" folder contains a "info.txt" file. So it is a folder inside folder structure. I have to zip this folder "data"(using php) along with the file and folder inside it, and download the zipped file. I have tried the examples available at http://www.php.net/manual/en/zip.examples.php These examples did not work. My PHP version is 5.2.10 Please help. I have written this code. <?php $zip = new ZipArchive; if ($zip->open('check/test2.zip',ZIPARCHIVE::CREATE) === TRUE) { if($zip

How do I archive multiple files into a .zip file using scala?

送分小仙女□ 提交于 2019-11-28 21:29:33
Could anyone post a simple snippet that does this? Files are text files, so compression would be nice rather than just archive the files. I have the filenames stored in an iterable. There's not currently any way to do this kind of thing from the standard Scala library, but it's pretty easy to use java.util.zip : def zip(out: String, files: Iterable[String]) = { import java.io.{ BufferedInputStream, FileInputStream, FileOutputStream } import java.util.zip.{ ZipEntry, ZipOutputStream } val zip = new ZipOutputStream(new FileOutputStream(out)) files.foreach { name => zip.putNextEntry(new ZipEntry

zipfile.BadZipFile: Bad CRC-32 when extracting a password protected .zip & .zip goes corrupt on extract

我们两清 提交于 2019-11-28 10:34:49
问题 I am trying to extract a password protected .zip which has a .txt document (Say Congrats.txt for this case). Now Congrats.txt has text in it thus its not 0kb in size. Its placed in a .zip (For the sake of the thread lets name this .zip zipv1.zip ) with the password dominique for the sake of this thread. That password is stored among other words and names within another .txt (Which we'll name it as file.txt for the sake of this question). Now if I run the code below by doing python Program.py

Opening downloaded zip file creates cpgz file?

て烟熏妆下的殇ゞ 提交于 2019-11-28 10:08:12
If I make the url for a zip file the href of a link and click the link, my zip file gets downloaded and opening it gets the contents as I expect. Here's that HTML: <a href="http://mysite.com/uploads/my-archive.zip">download zip</a> The problem is I'd like the link to point to my application such that I could determine whether the user is authorized to access this zip file. so I'd like my HTML to be this: <a href="/canDownload">download zip</a> and my PHP for the /canDownload page: //business logic to determine if user can download if($yesCanDownload){ $archive='https://mysite.com/uploads/my

How can I convert byte array to ZIP file

久未见 提交于 2019-11-28 09:22:29
I am trying to convert an array of bytes into a ZIP file. I got bytes using the following code: byte[] originalContentBytes= new Verification().readBytesFromAFile(new File("E://file.zip")); private byte[] readBytesFromAFile(File file) { int start = 0; int length = 1024; int offset = -1; byte[] buffer = new byte[length]; try { //convert the file content into a byte array FileInputStream fileInuptStream = new FileInputStream(file); BufferedInputStream bufferedInputStream = new BufferedInputStream( fileInuptStream); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); while

Set permissions on a compressed file in python

冷暖自知 提交于 2019-11-28 07:42:11
问题 I have a file test.txt that is inside a zip archive test.zip . The permissions on test.txt are out of my control when it's compressed, but now I want them to be group-writeable. I am extracting the file with Python, and don't want to escape out to the shell. EDIT: Here's what I've got so far: import zipfile z = zipfile.ZipFile('test.zip', 'w') zi = zipfile.ZipInfo('test.txt') zi.external_attr = 0777 << 16L z.writestr(zi, 'FOO') z.close() z = zipfile.ZipFile('test.zip', 'r') for name in z

how to download a zip file

ぃ、小莉子 提交于 2019-11-28 07:32:07
I am trying to download a zip file from my web api controller. It is returning the file but I am getting a message the zipfile is invalid when i try to open. I have seen other posts about this and the response was adding the responseType: 'arraybuffer'. Still isn't working for me. I'm not getting any errors in the console either. var model = $scope.selection; var res = $http.post('/api/apiZipPipeLine/', model) res.success(function (response, status, headers, config) { saveAs(new Blob([response], { type: "application/octet-stream", responseType: 'arraybuffer' }), 'reports.zip');

How to Unzip all .Zip file from Folder using C# 4.0 and without using any OpenSource Dll?

安稳与你 提交于 2019-11-28 07:31:00
I have a folder containing .ZIP files . Now, I want to Extract the ZIP Files to specific folders using C#, but without using any external assembly or the .Net Framework 4.5. I have searched, but not found any solution for unpacking *.zip files using Framework 4.0 or below. I tried GZipStream, but it only supports .gz and not .zip files. Denys Denysenko Here is example from msdn . System.IO.Compression.ZipFile is made just for that: using System; using System.IO; using System.IO.Compression; namespace ConsoleApplication { class Program { static void Main(string[] args) { string startPath = @"c:

Correctly decoding zip entry file names — CP437, UTF-8 or?

一曲冷凌霜 提交于 2019-11-28 07:20:45
问题 I recently wrote a zip file I/O library called zipzap, but I'm struggling with correctly decoding zip entry file names from arbitrary zip files. Now, the PKWARE spec states: D.1 The ZIP format has historically supported only the original IBM PC character encoding set, commonly referred to as IBM Code Page 437... D.2 If general purpose bit 11 is unset, the file name and comment should conform to the original ZIP character encoding. If general purpose bit 11 is set, the filename and comment

How do I delete or replace a file in a zip archive?

回眸只為那壹抹淺笑 提交于 2019-11-28 07:19:08
问题 I'm creating a program in Python which downloads a set of files and puts them into an archive with the zipfile module. I already found out how to append to the archive, but there are cases where the files in the archive already exist and should be overwritten. Currently, if I append an already existing file to the archive I get a duplicate. Does anyone know how to delete a file in an archive? 回答1: From http://docs.python.org/2/library/zipfile ZipFile.namelist() Return a list of archive