1

I'm making an image gallery script with PHP which is including a comment system. The basic function of the script is to read the folder's name and to show a gallery with the folder's name as title and it's images.

The problem is, that the comment system, which is made with mysql saves a comment like this:

ID | Folder | Image

This works great, but when I change the name of the folder, the script isn't working because there is set the wrong foldername in the Mysql table. Also when I just save the image's name there is the possibillity of having two pictures in diffrent folders with the same name.

Is it possible to identify a folder without using it's name?

//Note:

Thank you for your help, I think I found a solution. Now I just save the md5 hash of the image and save it in the Database instead of the foldername.

Sevi
  • 11
  • 2

4 Answers4

1

I guess it's better use another table where you'll save folders ids and their names folder_id | folder_name Something like that. Relying on folder names is not a good practice

kos
  • 478
  • 2
  • 10
  • And if the folder name is changed? – d-_-b Apr 04 '11 at 14:24
  • Change it in the table either. It's always better to use some simple unchangeable identification system – kos Apr 04 '11 at 14:28
  • Then he should probably use the very same PHP script to change the dir name. – d-_-b Apr 04 '11 at 14:29
  • It's just an option. There is also an option to use base64 encoding/decoding for folder names and many others. But still i like relying on database better, up to one's preferences – kos Apr 04 '11 at 14:33
1

No. You need to synchronize your filesystem with your database. Whenever you rename/remove/edit a folder, update its entry in the mysql database.

CoolStraw
  • 5,282
  • 8
  • 42
  • 64
1

One possibility could be to look at using a checksum of the image contents as a unique identifier. As long as the content doesn't change then you should be OK. As far as identifying changing names of the folders I can't think of any cunning way of detecting this unless you look at using a hash that 's a function of the files contained in it.

I think to be honest that it would be good to re-think the way you're storing/identifying these items in the database.

James C
  • 14,047
  • 1
  • 34
  • 43
0

You could always just do it this way:

Create 3 tables:

  • galleries -> with the columns (id,title)
  • files -> with the columns (id, gallery, name, filename)
  • comments -> with the columns (id, file_id, comment)

You would then create all your galleries with their name in the "galleries" table. When you created the gallery you would put all the images that you want to display in a folder, for example uploads/. You would then insert the name of the file (Maybe generate random filenames too) in the database along with it's real name. For example "Dolphins at Beach" could point to dolphins1234142.png that's in the uploads folder. All your comments would then be in the comments table where you would setup a relationship to the files table. This will allow you to have comments for a certain image.

Just my view on a gallery system, hope it makes sense.

Johann du Toit
  • 2,609
  • 2
  • 16
  • 31