Earlier i was displayed the image by referring current directory. My current directory is '/opt/lampp/htdocs/cms/'. My images was placed in the folder called 'Images' inside the cms folder. So, i have displayed the images by referring "./images/filename.png". Now i have moved the images outside of cms folder. Now i kept the images folder inside htdocs directory. Now i refer the path by '/opt/lampp/htdocs/Images/filename.png'. but now the images was not displayed.

<?php
$ImagePath = "/opt/lampp/htdocs/Images/test1_01.png";
?>
<IMG width="180" height="120" align="right" alt="No Image" src="<?php echo $ImagePath; ?>" />

Recommended Answers

All 3 Replies

/ in this case refers to the root folder of your lampp installation,
usually /whatever/htdocs, not the root of your current physical drive,
php cannot see any part of the drive outside the http root by drive structure, else / on my .com would be the server root, not my site root
If lampp is installed default the 'dos' equiv path the server expects when you key
/opt/lamp/htdocs/Images/test_01.png
is
/opt/lamp/htdocs/opt/lamp/htdocs/Images/test_01.png

from /opt/lampp/htdocs/cms/
to /opt/lampp/htdocs/Images/test1_01.png
is ../images/test_01.png

hope this makes sense

I have already tried it and works fine. But in my case, Images folder may be present in anywhere in the file system. For eg., if it was present in /home/arun/PreEncryptor/outputdir, how can i refer the image?

examine the file:// protocol perhaps, or cascade .. to the root
from /opt/lampp/htdocs/cms/
to root of the drive is
../../../..
so the new url is ../../../../home/arun/PreEncryptor/outputdir/image.png
not so hard in php where anything that repeats or is reused, can be
eg

<?php $path ="../../../../home/arun/PreEncryptor/outputdir/";
//code to get filenames from somewhere
echo $path.$filename;
echo $path.$filename2;
echo $path.$filename3; 
// and some code to do something interesting with them
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.