How can i show the images outside the web root directory in my php application?

前端 未结 4 884
长情又很酷
长情又很酷 2021-01-05 06:49

I have web application in PHP using apache server, linux. For some security reason i am keeping the documents and images outside web root. How can i show these images, when

4条回答
  •  花落未央
    2021-01-05 07:32

    As simple as that, this will output the image with correct headers,
    remember that you have to set the header() before flushing anything out of the output buffer
    => no echo or print before

    $file = '../../somedirectory/image.jpg‘;
    header('Content-Type:image/jpeg‘);
    header('Content-Length: '.filesize($file));
    echo file_get_contents($file);
    

提交回复
热议问题