Welcome Guest, Not a member yet? Register   Sign In
Force download file inside zip archive
#1

My website has a folder with a lot of zip files in it. I want to make a page where the user sees a list of the files inside a selected zip file, with the option to download (save or open) a specific file.
By doing that, it will be easier for some users who don't know how to handle zip files.
Any ideas?
Reply
#2

You could probably use the zip library to handle most of this. However, if it's going to be an extensively-used feature on your site, you may want to consider keeping the extracted content of the zip files on the server as well as the zip files themselves (and keeping the content and source files in synch) rather than using the zip library to read and extract the content as the user requests it.

The directory helper comes in very handy when you need a list of files in a directory.
Reply
#3

Thanks @mwhitney. I figured out that the native php ziparchive library has the correct methods to do the job.

PHP Code:
$unzipfolder 'media/unzipped/' $userid;
$zf 'example.zip';
chmod($zf,0777);
$zip = new ZipArchive;
if (
$zip->open($zf) === TRUE) {
 $zip->extractTo($unzipfolder '/');
 $zip->close();
 $z_content directory_map($unzipfolder);

In this example, I have a zip-archive called example.zip.
I'm creating a new zip object.
If this can successfully open the zipfile, it unzips (extractTo) the zipfile to a specified folder.
With the directory helper I can read the contents of that folder.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB