dongqu4443 2018-12-24 03:04
浏览 32
已采纳

来自脚本文件夹外部的访问图像文件中的问题

Problem: Hard to synchronise image between 2 folder

My project has 2 image folder:

Home/user/public_html/image

Home/user/m.fruit.com/image

public_html serves the main page for desktop version

m.fruit.com serves the mobile page

Both version serves the same images.

When I have new fruit image, I need to put it into both folder. This becomes double work...

my way of accessing image for desktop version is: (index.php in public_html folder)

 <img id="image" src="image/<?php echo $image; ?>.jpg">

my way of accessing image for mobile version is: (index.php in m.fruit.com folder)

 <img id="image" src="image/<?php echo $image; ?>.jpg">

For mobile version, I did try to access image in public_html so that I don't need 2 image folder. But it seems like not possible:

   <img id="image" src="public_html/image/<?php echo $image; ?>.jpg">  

Is there any way to use only 1 image folder to serves these 2 version of website instead of 2 in this case?

Other better solution also welcomed.

  • 写回答

3条回答 默认 最新

  • dongyupen6269 2018-12-24 07:08
    关注

    First, you can set base URL: like

      define('BASE_URL', 'http://example.com/');
    

    then set image src:

     <img src="<?php echo BASE_URL ?>image/imagename.jpg ">
    

    or create a helper function: PHP CODE

    function asset(path){
       return BASE_URL . path;
    }
    

    HTML CODE:

     <img src="<?php echo asset('image/imagename.jpg'); ?> ">
    

    This will work on both sides.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法