整理网站上的图片
我正在设计一个网站,其中会涉及太多照片。
有两个模块餐厅和菜肴。创建目录 strcuture 的最佳方法是什么?
图片/餐厅/ID images/Dishes/ID
我使用以下内容创建文件名
function imgName($imgExtension)
{
return time() . substr(md5(microtime()), 0, 12) . ".".$imgExtension;
}
ii 想要两个不同大小的缩略图。命名缩略图的最佳方式是什么?
因为数据库仅保存带扩展名的主图片文件名。
I am designing a website which will involve too many photos.
There are two modules Restaurants and Dishes. which is the best way to create the directory strcuture ?
images/Restaurants/ID
images/Dishes/ID
am using the following to create the filename
function imgName($imgExtension)
{
return time() . substr(md5(microtime()), 0, 12) . ".".$imgExtension;
}
ii want two different sized thumbnails. which is the best way to name the thumbnails ?
since the db will hold only the main pictures filename with extension.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不会太担心目录结构,你所拥有的看起来不错,甚至更好的是使用 S3 存储桶。
至于文件名部分,我发现最简单的方法是在缩略图文件名中添加 thumb_ 。所以:
somefilename.jpg
->thumb_somefilename.jpg
这样您就可以将
somefilename.jpg
存储在数据库中,并且在需要拇指时只需将额外的部分添加到前面即可。I wouldn't worry too much about the directory structure, what you have seems good, even better might be to use S3 buckets.
As for the filename part, I've found the simplest way is to prepend
thumb_
to the thumb filename. So:somefilename.jpg
->thumb_somefilename.jpg
This way you can store
somefilename.jpg
in the database and simply add the extra part to the front when you want the thumb.有什么理由像这样随机化文件名吗?我个人认为,你不应该一开始就给它们起随机的名字,它们应该与图片中的实际内容相关——仅仅是因为它对用户来说更好,对搜索引擎更有意义。
在完美的世界中,您将拥有一个逻辑结构,例如
菜肴/餐厅名称是一个独特的鼻涕虫。不过,这在现实世界中几乎不可能实现,因此
需要采取公平的妥协来避免冲突。
我通常把拇指放在自己的拇指/目录下,这样我就可以在所有位置使用相同的文件名(懒惰比什么都重要):
但是thenduks的前置建议也有效,这实际上只是个人喜好。
Is there any reason for randomising the filenames like this? It's my personal opinion that you shouldn't be giving them random names in the first place, they should relate to what's actually in the picture - simply because it's nicer for users and it's more meaningful to search engines.
In a perfect world you'd have a logical structure like
where the dish / restaurant name is a unique slug. That's pretty much impossible to implement in the real world, though, so
is a fair compromise to avoid collisions.
Thumbs I generally put under their own thumbs/ directory so I can use the same filenames in all locations (laziness more than anything):
but thenduks' prepending suggestion works too, it's really just personal preference.