mysql - Access folder and select filename using PHP -


i have written code, user selects profile picture , picture stored in localhost/user/$username/photos/photo1.gif.

after that, assigned filename (photo1.gif) session variable can display php scripts. working fine. can display picture in every php script accessing session variable.

the problem have when trying login login page: in login page connect database, retrieve email , password, check them , if ok redirect user home.php. problem user's photo not linked email cannot know filename of photo. thing know sure directory (because can retrieve username database well).

lets user has uploaded 4 photos (photo1, photo2, photo3, photo4 - photo4 uploaded last). makes sense using photo4 profile picture. there way me access folder , retrieve filename of picture uploaded last?

also, general question, better, store photos(or files) in database or server?

a few options:

it 'better' create photo table , store user_id , photo location in table. storing actual photo in table blob not recommended.

alternatively, avoid more tables, rename photos

username_photo1.jpg username_photo2.jpg username_photo3.jpg 

and can retrieve largest of them.

finally, option file creation date of photos in directory , take recent photo.

see getting filenames of files in folder


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -