0

I used this simple php gallery from a folder on my Joomla 3 site. Now I'm getting ready to do an update to Joomla 4 and I noticed that I have a problem with displaying images from the directory. if I add "echo $dir;" to test it gives me the correct path, although the image is not displayed. When I click "Open image in new tab" on the space where the image should be, the "Joomla Menu alias" is added to the correct path of the image and no image again.

I would note that this code worked fine on Joomla 3. Where is the error? Note: $alias2 is defined before, but I didn't copy that part of the code because it's irrelevant

 // (B) GET IMAGES IN GALLERY FOLDER 
$current_directory = getcwd();
$dir = $current_directory . '/2000/images/' . $alias2 . '/tmp/';
$images = glob("$dir*.{jpg,jpeg,gif,png,bmp,webp}", GLOB_BRACE);

  // (C) OUTPUT IMAGES
$imageCount = count($images);

 foreach ($images as $i) {
   $img = basename($i);
   $caption = substr($img, 0, strrpos($img, "."));
   printf("<figure><img src='2000/images/".$alias2."/tmp/%s'><figcaption>%s</figcaption>", 
     rawurlencode($img), $caption
   );
   }
   ?>
</div>

4
  • There doesn't appear to be any part of your code posted that is using Joomla, either 3 or 4, which makes me ask have you also changed the PHP version or are testing on a different environment?
    – Irata
    Oct 7 at 8:21
  • No. same php version, and same server
    – Midhat
    Oct 7 at 9:16
  • Is it just a copy mistake that the HTML <figure> element is not closed in your code with </figure>?
    – Zollie
    Oct 7 at 11:00
  • The element is closed in code not shown here
    – Midhat
    Oct 7 at 14:20

1 Answer 1

0

The problem was in this line of code:

printf("<figure><img src='2000/images/".$alias2."/tmp/%s'><figcaption>%s</figcaption>", 
     rawurlencode($img), $caption 

I typed the full url here and it works now.

Thanks everyone

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.