UPDATED: My question has been closed. But the solution someone provided (the question that's been already asked) does not solve my problem. I have already tried single quotes, double quotes etc as stated in someone's else answer. Can someone please open my question?:)
I am using PHP. This is the code I am using to display the image.
echo '<img src="$saving" width="100" height="100" alt="Random image" />' . "<br /><br />";
Here $saving is : userPosts/hemlata993/94/5f2628f30cc623.13126045.jpg
The /5f2628f30cc623.13126045.jpg
is the image name and it changed everytime it loops through to display next image.
The problem here is: If I write userPosts/hemlata993/94/5f2628f30cc623.13126045.jpg
it works, but that's the same thing is inside $saving
variable as I printed it out on website and copied this userPosts/hemlata993/94/5f2628f30cc623.13126045.jpg
and pasted it in image src to see and it works. Why is it not working when I write the variable name but works if I write the variable content?
I am basically trying to loop through folders and their images and printing it out on the website. It prints out all the name of images along the path correctly.
My full code:
$image = 'userPosts/hemlata993';
function listFolderFiles($dir){
$ffs = scandir($dir);
unset($ffs[array_search('.', $ffs, true)]);
unset($ffs[array_search('..', $ffs, true)]);
// prevent empty ordered elements
if (count($ffs) < 1)
return;
echo '<ol>';
foreach($ffs as $ff){
echo '<li>'.$ff;
$saving = "$dir/$ff";
$saving .= '<li>'.$ff;
echo "$saving";
echo '<img src="$saving" width="100" height="100" alt="Random image" />' . "<br /><br />";
if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);
echo '</li>';
}
echo '</ol>';
}
listFolderFiles($image);