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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:21:05+00:00 2026-06-18T12:21:05+00:00

I recently started to develop a pretty huge site. On the site i would

  • 0

I recently started to develop a pretty huge site.
On the site i would like to allow users to upload their sample works.
We are pretty limited at the moment so the images will be stored on our server.

I am a bit stuck with the logic.
So my logic would be this.

User creates a folder with a name that is stored in the database with the users id attached to it

folder table

Rows

id | folder        | user_id 
1  | Some folder   | 1
2  | New folder    | 4
3  | Nother folder | 7

Images table

Rows

id | image_name        | folder_id |
1  | image1.jpg        | 1
2  | image2.jpg        | 1
3  | image3.jpg        | 1
4  | image4.jpg        | 2
5  | image5.jpg        | 2
6  | image6.jpg        | 2

Relations

class Folder extends Eloquent 
{
    public function images()
    {
        return static::has_many('Images');
    }
}

class Image extends Eloquent 
{
    public function folder()
    {
        return static::belongs_to('Folder');
    }
}

folder structure on server

- samples
  -user_id
   - folder_id
     - image1
     - image2
     - image3

so as you can see, user creates a folder, after the folder is created, user uploades the image name in to the database with the folders id, and showing the images would be the way describe above with the realation.

So my questions.

  • Is this a good logic in your opinion
  • can this lead problems in the future
  • what woud you offer for this functionality

And what i am most sacred of are 2 things.

I think this will lead to a huge database, second are the id's, after x time when there will be more users, the id's will increase, and i know this will sound strange, but since lot of users will upload images will lead to huge id’s, what i mean by this it will maybe reach millions, is there a way to solve this problem?

Thank you for the help

  • 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-06-18T12:21:06+00:00Added an answer on June 18, 2026 at 12:21 pm

    Ok – lets break this down into a few sub-answers;

    Question:

    - Is this a good logic in your opinion
    - Can this lead problems in the future
    - What would you offer for this functionality
    

    Answer:

    The logic seems sounds – but I’m curious where you will store the images? Inside public_html – or outside the web root? If you have the images inside public_html – and allow the browser to access them directly, it will allow users to ‘guess’ other user folders and access those. You need to store the data securely.

    To make images outside the webroot, and make sure only authorized users can access them – you should use readfile(). Something like this will do the trick

    function user_file($file_name = "")
    {
        if ($file_name)
        {
             // Ensure no funny business names to prevent directory transversal etc.
             $file_name = str_replace ('..', '', $file_name);
             $file_name = str_replace ('/', '', $file_name);
    
             // now do the logic to check user is logged in
             if (Auth::check())
             {
                    // Serve file via readfile() - we hard code the user_ID - so they
                    // can only get to their own images
                   readfile('../your_app/samples/'.Auth::user()->id.'/'.$file);
             }
        }
    }
    

    Question:

    I think this will lead to a huge database, second are the id’s, after x time when there will be more users, the id’s will increase, and i know this will sound strange, but since lot of users will upload images will lead to huge id’s, what i mean by this it will maybe reach millions

    Answer:

    According to the mySQL features page:

    We use MySQL Server with databases that contain 50 million records. We also know of users who use MySQL Server with 200,000 tables and about 5,000,000,000 rows.

    So thats 5 billion rows. You will maybe get to a few million. So you are safe here (depending upon your hardware).

    Question:

    …but since lot of users will upload images will lead to huge id’s,
    what i mean by this it will maybe reach millions, is there a way to
    solve this problem?

    Answer:

    If you dont want to store millions of records, and your worried about performance, one option is to keep the folder table, but drop the image table. Instead you can use scandir() on the folder – and get PHP to retrieve the file names from the directory itself. Then you dont have as much overhead.

    <?php
        $list_of_user_files = scandir("$user_id/$folder_id");
        foreach ($list_of_user_files as $file) {
              echo "File: $file <br>";
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started maintaining a .Net 1.1 project and would like to convert it
I've been programming for a while, but I just recently started to develop application
When I started to develop with .NET under VS2008 recently, I was very happy
I recently started learning backbone and was wondering what would be the best way
I have recently started to develop applications for iPhone with MonoTouch and have to
I recently started using eclipse and an AVD emulator to develop android apps for
I've recently started on a project to develop some portlets which will run on
I have a brief conceptional question: Recently, I started to develop an app in
Background I've recently started to develop some code using the NDK, and I've thought
I recently started working on a small CMS. I usually develop .NET applications in

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.