Avatar of PLCITS
PLCITS
 asked on

Good Example of upload files in PHP

I need a really good example in PHP (maybe something somebody implements before in a web app) to implement in a little program, where the user can upload files, we are using PHP, MySQL,  the files can be saved in the database as a binary or physical in the server  whichever is best
Web ApplicationsDatabasesPHP

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
SOLUTION
lenamtl

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bernard Savonet

As a good practice, in general Do NOT upload file into a SQL DB

Why?
1 - it has usually a variable lenght and will therefor impact optimization and performance
2 - you always run the risk that some programmer will not use the recommended good paractice to read a list of fields, but instead to read the complete row / record.... which will severely impact the program performance in unexpected (by the programmer) ways

Recommended practice is to have a donwload area, and to place inti the db a link to the file
lenamtl

Hi,

Here is my method that save a lot of ressource.

I saved file per client or project
I never put all files in one directory
I would create a directory per project or per contact
I always rename the file using timestamp this prevent a lot of problem and each file have unique name.

I saved all file information into the DB:
file size,
file mime,
original name, (so user will see the original file name)
new name (this will be use to find the phisical file let say for unlink the file)
contact or project id,
uploder id,
upload date and time (timestamp)

I'm saving file size and mime to save ressources, getting info everytime using PHP this can slow down the system.
ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy