图片存储、上传、显示优化

1、图片路径写进配置文件,当路径有变动时【因业务扩大,服务器存储图片空间不足等】,只需修改配置文件,而不用修改代码

2、封装显示、上传、删除函数,实现代码重用

  【可类比其他类似的操作】

1、在/Common/Common/Conf/conf.php中,写入图片配置  C()

PHP.TP框架下商品项目的优化2-图片优化

2、把显示图片showImage()的功能封装到/Common/Common/function.php中

//显示图片
    function showImage($url, $width = '', $height = '')
    {
        $ic = C('IMAGE_CONFIG');    //读取配置文件
        if($width)
            $width = "width='$width'";    //显示宽度(html代码)
        if($height)
            $height = "height='$height'";
        echo "<img $width $height src='{$ic['viewPath']}$url' />";
    }
showImage()

相关文章:

  • 2021-10-31
  • 2022-12-23
  • 2021-12-15
  • 2021-11-24
  • 2021-08-11
  • 2021-12-27
  • 2021-08-31
猜你喜欢
  • 2021-06-25
  • 2022-01-01
  • 2021-08-15
  • 2021-07-29
  • 2021-11-09
  • 2021-12-16
  • 2021-11-23
相关资源
相似解决方案