开发者

Best way to store and deliver files on a CMS

开发者 https://www.devze.com 2023-01-02 05:46 出处:网络
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

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..


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.

0

精彩评论

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