SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Sep 2003
    Location
    Northern California
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Special unzip situation - is it possible?

    Our situation:

    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)
    widgets/file2.txt
    widgets/file3.txt

    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.
    Interactive Web Media - Trinity River
    Embrace the mobile lifestyle - SmartFreelancer.com

  2. #2
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2003
    Location
    Northern California
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Interactive Web Media - Trinity River
    Embrace the mobile lifestyle - SmartFreelancer.com

  4. #4
    <?php while(!sleep()){code();} G.Schuster's Avatar
    Join Date
    Mar 2007
    Location
    Germany
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Guru
    Join Date
    Sep 2003
    Location
    Northern California
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks - we're doing real-time data analysis and reporting as soon as files are uploaded
    Interactive Web Media - Trinity River
    Embrace the mobile lifestyle - SmartFreelancer.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •