0

I like to use php-include for the first time to include different partials within my static webpages. My folder structure is something like that:

-index.php
-other.php
----production
-------partials
-----------partial1.php
----public
-------images
-----------image1.png

And I want to reference the image from my partial1.php. So I try to do

<img src="../../public/images/image1.png">

but the reference doesn't work and I can add or delete as many "../" as I want, still not working. How else would I define a path to my public-folder and reference to that correctly?

2
  • If you index.php is in the "root" of your site simply use /public/images/image1.png to reference that image. Commented Apr 16, 2018 at 10:22
  • Your approach is correct from a technical point of view. Take a look at your http servers log files to find what URL the client translates the request to. A cleaner alternative would be to use an absolute path (/images/image1.png) as reference and define an Alias on the server side configuration for those requests. A ton of benefits if you decouple request paths from the actual physical layout on of the server side file heirarchy... Commented Apr 16, 2018 at 10:24

1 Answer 1

1

Try insert full path:

<img src=\"<?php echo @getcwd()."/public/images/image1.png" ?>\" />

or add other ../:

<img src="../../../public/images/image1.png">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.