Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3437178
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:02:00+00:00 2026-05-18T08:02:00+00:00

My users will be zipping up files which will look like this: TEMPLATE1.ZIP |———

  • 0

My users will be zipping up files which will look like this:

TEMPLATE1.ZIP
   |--------- UnknownName
                   |------- index.html
                   |------- images
                               |------- image1.jpg

I want to extract this zip file as follows:

/mysite/user_uploaded_templates/myrandomname/index.html
/mysite/user_uploaded_templates/myrandomname/images/image1.jpg

My trouble is with UnknownName – I do not know what it is beforehand and extracting everything to the “base” level breaks all the relative paths in index.html

How can I extract from this ZIP file the contents of UnknownName?

Is there anything better than:

1. Extract everything
2. Detect which "new subdidrectory" got created
3. mv newsubdir/* .
4. rmdir newsubdir/

If there is more than one subdirectory at UnknownName level, I can reject that user’s zip file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:02:00+00:00Added an answer on May 18, 2026 at 8:02 am

    I think your approach is a good one. Step 2 could be improved my extracting to a newly created directory (later deleted) so that “detection” is trivial.

    # Bash (minimally tested)
    tempdest=$(mktemp -d)
    unzip -d "$tempdest" TEMPLATE1.ZIP
    dir=("$tempdest"/*)
    if (( ${#dir[@]} == 1 )) && [[ -d $dir ]]
        # in Bash, etc., scalar $var is the same as ${var[0]}
        mv "$dir"/* /mysite/user_uploaded_templates/myrandomname
    else
        echo "rejected"
    fi
    rm -rf "$tempdest"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am programming a website in which users will have a number of settings,
Free users will get a url like user1.myapp.com The paid ones will be able
In my app users will be able to change element's border style attributes like
I am building an iOS app which users will be able to enter the
I have a PHP Script that users will enter a name like: Alex_Newton ,
I have some forms in which users will input some numbers, I want to
My site has urls like 'http://someRandomUsername.mysite.com'. Sometimes users will try urls like 'http://www.someRandomeUsername.mysite.com'. I'd
I would like to create a multilanguage landing page , users will get the
I am developing a site where users will have permalinks for them like user.domain.com
I am using Multi-line TextBox through which users will be able to enter data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.