mgm_03 — 2011-06-21T21:59:29-04:00 — #1
A person uploads a .zip file and it may contain more .zip files (inside of which are .txt files) and it may also have folders containing .txt files (not zipped).
E.g. Archive.zip might contain:
foo.zip (contains 4 text files)
bar.zip (contains 8 text files)
We need to extract all .txt files into 1 directory. We do not want to maintain the directory structure of the uploaded .zip
Is this possible and where should I be looking? My Google searches have resulted in tutorials or code to solve this unique situation.
Thanks in advance.
g_schuster — 2011-06-22T04:12:55-04:00 — #2
I'd extract "level by level" - the whole zip file into one dir and then iterate over the tree, renaming all "wanted files" to unique names and moving them to a destination dir.
While iterating you'll get the names of further zips so do the same with them, but probably to another temp dir to prevent overwriting anything.
This way there should be no problem with files with similar names in e.g. subdirectories or "sub-zipfiles".
The code itself doesn't differ from extracting a single zip, you'll only have to use e.g. RecursiveDirectoryIterator on the extracted file trees.
mgm_03 — 2011-06-22T10:30:26-04:00 — #3
Thanks for replying and suggestion. I will look into this more carefully. I was told that using the command line might be more efficient/powerful but that's out of my skillset.
g_schuster — 2011-06-22T10:33:12-04:00 — #4
Command line scripting with PHP is not much of a difference.
I'd go with a cronjob in most cases, so customers can upload a zip file and it'll be processed later by the cron.
mgm_03 — 2011-06-22T10:35:53-04:00 — #5
Thanks - we're doing real-time data analysis and reporting as soon as files are uploaded