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 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端