-1

I am implementing a php site that allows users to upload their pictures, I created the uploads directory at the same level as root but now how can I access those images in html. I tried following

<img src="../../uploads/<?=$filename?>">
  • Do you use a framework? Please write example web url that run your php code – ramin ashrafimanesh Jan 07 '18 at 10:44
  • Note that the "src" is required by the browser client, not processed by your server. – user202729 Jan 07 '18 at 10:46
  • no framework, http://ehtisham9.me/diary is the link. – Ehtisham Hassan Jan 07 '18 at 10:47
  • That is, whatever you put in the "src" part of the HTML tag is requested by the browser. If you put `../../uploads/abc` in the `src` field your browser will request the page `ehtisham9.me/diary/../../uploads/abc` for the image, and the server should put it there. – user202729 Jan 07 '18 at 10:49
  • @user202729 I used to do src="uploads/username.jpg" but now I moved that uploads folder out of the root directory (2 dir back) – Ehtisham Hassan Jan 07 '18 at 10:49
  • actually, i don't want anyone to just go and see all the images in upload dir like ehti**.com/uploads so I moved uploads to out of site's root directory i.e ehtisham**.com/ – Ehtisham Hassan Jan 07 '18 at 10:52

1 Answers1

0

Try making a root variable

If you are using php 5.3+

<?php 

$root =  __DIR__;

 ?>

 <img src="<?php echo $root ?>uploads/<?=$filename?>">

or set the $root variable to your domain name

Frosty
  • 299
  • 5
  • 31