【问题标题】:How To: Displayed image file name different than actual filename on server如何:显示的图像文件名与服务器上的实际文件名不同
【发布时间】:2010-12-18 04:07:02
【问题描述】:

我想显示一张图片,但文件名与服务器上的实际文件名不同。

ex) 用户通过查看源代码会看到<img src="/img/photos/Awesome_Picture_By_John.jpg">

但实际的文件名是 /img/photos/12b7dch2.jpg

感谢任何帮助。谢谢

【问题讨论】:

  • 你知道这与 JavaScript 有什么关系吗?

标签: php javascript html image file


【解决方案1】:

它可以很容易地完成。我想你可以用 mod_rewrite 做这样的事情,把现有的

/img/photos/Awesome_Picture_By_John.jpg

进入类似的东西

/img.php?id=Awesome_Picture_By_John

并让 img.php 从数据库中提取真实的文件名。

这里有一个很好的 mod_rewrite tutorial 可以帮助您入门。

【讨论】:

  • 这个链接必须在重写规则中保留多久?您可以使用 Awesome_Picture_By_John.jpg 的名称创建指向 12b7dch2.jpg 的符号链接。有没有可能想调用一些东西 Awesome_Picture_By_John.jpg?
  • 重写规则需要泛化,如:RewriteRule ^/img/photos/(.+)$ /serve_real_image_from_fancy_filename.php?fancy_filename=$1
猜你喜欢
  • 1970-01-01
  • 2018-02-14
  • 2013-01-10
  • 2010-12-08
  • 2023-03-31
  • 2012-03-25
  • 1970-01-01
  • 2010-10-09
  • 1970-01-01
相关资源
最近更新 更多