-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?>">
6
  • Do you use a framework? Please write example web url that run your php code Commented Jan 7, 2018 at 10:44
  • Note that the "src" is required by the browser client, not processed by your server. Commented Jan 7, 2018 at 10:46
  • no framework, ehtisham9.me/diary is the link. Commented Jan 7, 2018 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. Commented Jan 7, 2018 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) Commented Jan 7, 2018 at 10:49

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.