Find centralized, trusted content and collaborate around the technologies you use most. Connect and share knowledge within a single location that is structured and easy to search. I am trying to zip and download files from a folder named "upload".
Zip file is downloading but I couldn't open extract it. I am getting an error like "The archive is either in unknown format or damaged". I had spent more than 6 hours on this downloading zip files on my mac localhost - Though the file was getting downloaded, I could not unzip them getting cpgz files. Apparently, none of the solutions mentioned in stack overflow around a variety of questions on zip file download worked. Finally, after trial and error, I found that the following code works:.
If you are still having issues then you should check if you have write permission to the current directory. You can check the return value of close to check whether the file was actually written. You could also add extra validation to check whether the files you are adding to the zip actually exist and before sending check the zip file exists.
Answer is good but Please add these lines before header. Zip file is open in all zip software winzip, winrar etc. I have a client "download-all" button for files stored in a parallel directory on a webserver. Having similar issues to the OP, the following code was created after reading many similar posts.
The server is running php7. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. ZIP all files in directory and download generated. Asked 8 years, 4 months ago. Active 1 year, 6 months ago. Viewed 93k times. Todua Ygor Montenegro Ygor Montenegro 1 1 gold badge 11 11 silver badges 25 25 bronze badges.
Add a comment. Active Oldest Votes. Todua T. This is a good answer, but it's not based on the question that OP asked, in which he specified that he only cared about the single directories image files. Just thought that should be clarified as anyone who is trying to do exactly what OP asked would find this code does not do exactly that. Create ZipArchive Class object for Zip file creation. Define a function createZip to read files and directory from the specified directory path.
If the reading value is the file then add it to zip object using addFile method. If the value is a directory then create an empty directory and call createZip function where pass the directory path. View Demo.
0コメント