读取文件的元数据
我正在为 PHP 制作一个画廊实现。
管理员可以访问上传页面,上传图像并对其进行分类。到目前为止,一切都很好。
该实现将允许用户对管理员上传的图片发表评论,因此我正在实现一个数据库表来将评论与各自的图像链接起来。
id | path .:. id | datetime | comment_title | comment_body | uid
到目前为止,一切都很好。
我希望管理员能够重命名文件(不一定通过站点,而是通过 FTP 或其他根访问权限),并且不会破坏整个系统。
所以我正在考虑实现一个元数据系统来将 ID 与图像链接起来。这将为我节省第一个表,并允许自由操作图像(将其移动到文件夹内,重命名等)。
问题是,我该如何实施?如何写入附加到文件的元数据以及如何读取它?谷歌没有给出这方面的实际结果。
如果有更好的方法,我也很乐意听到!
将不胜感激任何帮助!
I am making a gallery implementation for PHP.
The administrator is able to access the upload page, where he would upload and categorize the image. So far so good.
The implementation will allow users to comment on the pictures the admin has uploaded, so I'm implementing a database table to link comments with their respective images.
id | path .:. id | datetime | comment_title | comment_body | uid
So far so good.
I want the administrator to have the ability to rename files (not necessarily via the site, but via FTP or otherwise root access), and not break the whole system.
So I was thinking of implementing a metadata system to link the ID with the image. That would save me both the first table, and will allow free manipulation of the image (both move it inside folders, rename it, etc).
The question is, how do I implement it? How do I write a metadata attached to a file, and how do I read it? Google gave no real results on this one.
If there's a better way of doing it, I'd love to hear as well!
Will appreciate any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我自己没有使用过,但 sourceforge 上的 XMP PHP 工具包听起来正是您可能正在寻找的: http://xmpphptoolkit .sourceforge.net/ 话虽这么说,它还是 alpha 版本,而且看起来已经有一年多没有更新了。
您还可以使用 iptcembed 将任意元数据写入图像文件。正如您在评论中提到的,这只适用于 JPEG 文件。
http://php.net/manual/en/function.iptcembed.php
下面是一个来自类注释的脚本,它将获取和设置 IPTC 数据:
读取版权字符串的示例:
更新版权声明:
While I have not used this myself the XMP PHP Toolkit on sourceforge sounds like just what you might be looking for: http://xmpphptoolkit.sourceforge.net/ That being said - it's in alpha and hasn't been updated in over a year it appears.
You are also be able to write arbitrary metadata to an image file with iptcembed. As you mention in your comment this only works for JPEG files.
http://php.net/manual/en/function.iptcembed.php
Here is a script from the comments of a class that will get and set IPTC data:
Example read copyright string:
Update copyright statement: