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

前端 未结 4 921
长情又很酷
长情又很酷 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:16

    For my application, none of those answers were working - I simply couldn't get the image to display and it wasn't really feasible for me to add a new php file to call because reasons. What DID work for me is

    $filename = read_filename_from_database;
    $fileDir = "/path/to/files/";
    $file = $fileDir . $filename;
    if (file_exists($file))
    {
         $b64image = base64_encode(file_get_contents($file));
         echo "";
    }
    

提交回复
热议问题