dtt5830659 2010-06-06 13:35
浏览 27
已采纳

在CMS上存储和传送文件的最佳方式

First of all, this isn't another question about storing images on DB vs file system. I'm already storing the images on the file system. I'm just struggling to find a better way to show them to all my users.

I' currently using this system. I generate a random filename using md5(uniqueid()), the problem that I'm facing, is that the image is then presented with a link like this:

<img src="/_Media/0027a0af636c57b75472b224d432c09c.jpg" />

As you can see this isn't the prettiest way to show a image ( or a file ), and the name doesn't say anything about the image.

I've been working with a CMS system at work, that stores all uploaded files on a single table, to access that image it uses something like this:

<img src="../getattachment/94173104-e03c-499b-b41c-b25ae05a8ee1/Menu-1/Escritorios.aspx?width=175&height=175" />

As you can see the path to the image, now has a meaning compared to the other one, the problem is that this put's a big strain in the DB, for example, in the last site I made, I have an area that has around 60 images, to show the 60 images, I would have to do at least 60 individual query's to the database, besides the other query's to retrieve the various content on the page.

I think you understand my dilemma, has anyone gone trough this problem, that can give me some pointers on how to solve this?

Thanks..

  • 写回答

1条回答 默认 最新

  • doufei8691 2010-06-06 13:41
    关注

    You could always use .htaccess to rewrite the url and strip the friendly name. So taking your example, you could display the image source as something like:

    /Media/0027a0af636c57b75472b224d432c09c/MyPictures/Venice.jpg
    

    You could use htaccess to actually request:

    /Media/0027a0af636c57b75472b224d432c09c.jpg
    

    The other option is to have a totally friendly name:

    /Media/MyPictures/Venice.jpg
    

    And redirect it to a PHP file which examines the url and generates the hash so that it then knows the actual image file name on the server. The php script should then set the content type, read the image and output it. The major downside of this method is that you may end up with collisions as you two images may have the same hash. Given that the same thing can also occur with you current method I assume it isn't an issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)