Hello,

I have tried to create a way though which users can create there own photo gallery but for that i created a code via whihc users can create their own folder but things a i want to do in a litle tricky way. Wank to allow users to create folder whiin the folder can anyone would to let me know hwo it can be done

Create folder

function create_gallery($connect) {
        $description  = $_POST['description'];
        $visibility   = $_POST['PrivacyLevel'];
        $id           = $_POST['uid'];
        $dirname      = $_POST["GalleryName"];
        $dirpath      = "./usersdata/".$dirname ;

        $create       = mkdir($dirpath, 0755, true);

        $insert_query = mysqli_query($connect, "INSERT INTO usersdata (uid, dir_name, description, visibility) VALUES ('$id', '$dirname', '$description', '$visibility')");

        if($insert_query) {
            $_SESSION["message"] = "Your New Gallery Created";
            header("Location: user.php?uid=".$_SESSION["uid"]);
        } else {
            $_SESSION["message"] = "Gallery Creation Failed";
            header("Location: user.php?uid=".$_SESSION["uid"]);
        }
    }

I don't get you very well can you please explain it further and can you please edit your question (full of mistakes, sorry)
.

I want to create a panel from where users can create folders.

galleries into folders, and folders into folders, up to five levels deep.

Member Avatar for diafol

Not sure how some of that question bypassed the profanity filter, heh heh. Perhaps wank isn't a naughty word in the US.

I'm assuming each user has his or her own directory.

Giving a user a unique directory (gallery) name should be simple. If you have unique ids for users, use that or even slugify the username - however take care if you do that as different usernames can produce the same slugs.

Creating directories is straightforward (mkdir) - you shouldn't have to store those directorynames in a DB, if they are under the user's main gallery directory (e.g. user_id). Do you have a GUI like a file tree? There are many 3rd party scripts out there that allow the creation, deletion, renaming, moving etc of directories and files. The only issue here is if you're storing file metadata in a DB. If the path/name changes, then the DB record must change too. This could be tricky.

Then there's the "guest view" - where other users get to see other users' files (do you allow this?). Will you have a similar situation where you have some sort of Explorer-style fileview (thumbs?). If so, will your urls change as users traverse the directories? If so, again this could be tricky and you may need to limit directory names to slug-friendlies.

e.g. www.example.com/usergalleries/26478/flowers/pansies

This will need some htaccess fairy dust.

IMPT: you have not sanitized your input data. Use a prepared statement NOT this! You are wide open to SQL injection.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.