How to handle incremental folder upload in Laravel like on google drive?
For instance, if Images folder already exist and the user uploads Images folder it would be Images (1). And if the user uploads the folder again it would be Images (2)

Would the logic be to check the database if the folder exist already and also use regex to find the pattern name ([09]) to query the database and get the descending name ordered naturally. Then get the number only from this and add 1 to make sure the next folder would be something like Images (6)
In the frontend, the app send these to the API and web directory is being used to upload the
folder
folderPath: Images/flowers/1.png
parentId: 67
token: Yue4gey5737
Database schema
folders
name
parent_id
token
files
name
folder_id
The algorithm goes through each folderPath like Images and then flowers and finally 1.png
It checks firstly if the name exist and increments with prefix (1) and creates a folder in the database. Then, it reference the is of the Images and creates another folder and assign this as parent id and finally uses the is of this folder and assigns it as folder id while creating a file entry in the database.
The token is used to check that any subsequent folder path is not considered as duplicate. For instance
folderPath: Images/flowers/2.png
parentId: 67
token: Yue4gey5737
The algorithm again has to go thrift the images, folders and then process 2.png

The token would be used to ignore any folder name that has the same token.
Is there a better way to implement this?
Don’t, just upload a zip folder and store it or allow them to upload multiple files and let them choose a directory that you have set up securely, laravel upload system or symfony is appropriate both from technical and security standpoint
r/phphelp bro
Members
Online

source