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 897433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:53:15+00:00 2026-05-15T14:53:15+00:00

I am trying to make a script that lists only folders within a folder.

  • 0

I am trying to make a script that lists only folders within a folder. The thing is that I have users who can create folders within their folders so basically what I’m trying to do is to have a way for users to manage their folders and storing files… My problem is that I want to make php “think” that the root folder is their home directory and they cannot go upper than their home directory. Currently my php function doesn’t do that, it only shows the content of the directory…and if the user goes one level up and again one level up …and so on….he could browse the entire hard drive.

function directoryList($path) {
    $dirStruct = array();
    if(is_dir($path)) {
        $handle = opendir($path);
        while(($file = readdir($handle)) !== false) {
            if(@opendir($path.$file)) {
                chdir($path.$file);
                $absolutepath = getcwd();
                $dirStruct[] = array('path' => $absolutepath.'\\', 'name'=>$file);
            }
        }
    }
    return $dirStruct;
}
  • 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-15T14:53:16+00:00Added an answer on May 15, 2026 at 2:53 pm

    Instead of giving the user an absolute path, only allow them to specify paths which are relative to a given base path. Next, write a function which removes any “/../” for the relative path and you’re safe (as long as users can’t create links on the server …).

    If you want to be nice, you can match the “..” with the element before that (so “a/../b” would become “b”, i.e. the “..” remove the “a”) or ignore the “..” if there is no path element before it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP upload script and am trying to make it so that
hello everyone I am trying to make a script that steps through a list
I'm trying to make a script that will prompt the user and wait for
I'm trying to make a script that automatically starts uploading after the data has
I'm trying to make a script that will go into a directory and run
I'm trying to make a PHP script that will take a potentially infinite number
I'm trying to make a PHP script that will check the HTTP status of
I'm trying to make a small Python script that is executed by clicking an
OK basicly what I am trying to do is make a script that will
I have an array that lists folders in a directory. Until now, I've been

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.