【问题标题】:How to keep flexibility between .jpg and .jpeg file extension如何在 .jpg 和 .jpeg 文件扩展名之间保持灵活性
【发布时间】:2017-12-15 20:58:03
【问题描述】:

我正在使用 C# 开发网站。我有存储照片路径的数据库。但问题是存储路径就像 .../assets/photo_name.jpg 和我的资产文件夹有扩展名为 photo_name.jpeg 的照片。 因此,当我从数据库中获取照片路径并将其放入 src 中的<img> 标记时,由于 .jpg 和 .jpeg 之间的冲突,我无法显示照片。

cmd.CommandText = "SELECT icon FROM  `tbl_vc` WHERE is_current =  'Y' AND chancellor =335";
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
adp.Fill(set);
icon_src  ="<img src='"+icon+"' width='331px' height='381px' /> </figure>";

【问题讨论】:

  • 嗯..使用Replace(".jpg",".jpeg")?

标签: c# html image web jpeg


【解决方案1】:

你可以检查文件是否存在

bool fileExists = File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/"+ icon));
icon_src = "<img src='" + fileExists ? icon : icon.Replace(".jpg", ".jpeg") + "' width='331px' height='381px' /> </figure>";

【讨论】:

    猜你喜欢
    • 2013-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多