Serving images from outside of document root

后端 未结 2 1624
既然无缘
既然无缘 2020-12-19 01:51

Is it possible?

Let\'s say my directory structure looks like this:

/data
    /data/images
/public

The document root is in the \"pub

相关标签:
2条回答
  • 2020-12-19 02:11

    Another way (say if you can't set an alias...) would be to use a script as the image source eg:

    <img src="image.php?img=myImage.jpg" />
    

    image.php would be similar to:

    <?php
      header('Content-Type: image/jpg');
      readfile("../img/" . $_GET['img']);
    ?>
    

    Of course you'd need to extend the script to filter $_GET['img'], as well as detect and set the right content type. Your script could even resize the image according to other parameters passed in the query string.

    0 讨论(0)
  • 2020-12-19 02:26

    The most common way is an Alias:

    Alias /data/ /wherever/your/data/are/
    
    0 讨论(0)
提交回复
热议问题