Stijn_d
Stijn_d

Reputation: 1088

PHP Large Files Zipping with folders that don't exist in the file-system

I'm creating some kind of file-sharing application. In this application you should be able to up-& download files and structure these files.

I've opted to not keep on manipulating the file-system. But I Upload the files into folders based on timestamps, and store the important information in the database and structure them inside the DB. So there are no REAL subfolders, just relations in the database to structure thes files into folders.

No I want to let users download folders (including subfolders) by zipping it. But I want to recreate this folder-structure(that the user sees in the front-end) inside the zip-archive that will be downloaded. I've managed to do this using the ZipArchive class of PHP: http://php.net/manual/en/class.ziparchive.php But there's 1 big issue with this. It uses a lot of memory & cpu when compressing big files. And the system must be able to handle large files (>1GB) I can't possibly allow PHP to use >1GB of memory?!

Now I've found a Stackoverflow question to zip large files using less memory in php: https://stackoverflow.com/a/4357904/383731

This seems to use the Unix Zip command, But is it possible to create folders inside these zips without them existing inside the file-system?

Upvotes: 0

Views: 256

Answers (1)

Oliver A.
Oliver A.

Reputation: 2900

  • create a folder in your temp directory
  • add subfolders and links to real files
  • zip it
  • send it
  • kill temp files

The part about the links is important. If you just use links you do not actually have to copy the file contents. All you do is give the zip tool a hint where it can find the contents you want to include in the archive

EDIT:

Both symbolic links and hard links work, The link above explains how to do it with symlinks.

Upvotes: 1

Related Questions