I tried serving images outside of the web root and it worked. Here's what I did:
Directories:
app
|_upload_dir
|_user_img_dir
|_ user1.jpg
|_ other_img_dir
|_an_img.png
Public_html
|_asset_dir
|_load_image.php
|_home.php
load_image.php
<?php
$mime_type = mime_content_type("../app/upload_dir/user_imag_dir/{$_GET['image']}");
header('Content-Type: '.$mime_type);
readfile("../app/upload_dir/user_img_dir/{$_GET['image']}");
?>
HTML
...
<body>
<img src="/load_image.php?image=user1.jpg" width="100" height="100"/>
</body
...
That's how I can read the images from user_img_dir
directory.
So how can I read any files inside upload_dir
? should I have multiple load_image.php
typeScript for each directory? Or, should I pass the whole path inside '$_GET'
? Or there is a better way? I need a direction here.
Thank you.