开发者

Identify folder with PHP

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开发者_如何学Python 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.


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


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜