0

I can list all the images from a folder in json using the code below:

<?php

$dir = "images/friday/";
$images = glob($dir."*.jpg");

foreach($images as $image){
  $registro = array(
    "FILE" => $image
  );
  $retorno[] = $registro;
}

$retorno = json_encode($retorno);
echo $retorno;

?>

I think it would work with directories too but nothing is displayed if I don´t use print_r($dirs).

<?php

  $path = "images";
  $dirs = glob($path . "/*", GLOB_ONLYDIR);

  foreach($dirs as $dir){
    $reg = array(
     "FOLDER" => $dir
     );

    $return[] = $reg;
  }

  $return = json_encode($return);
  echo $return;

?>

echo $return does not display anything. Is there a simple workaround or I have to build something like this function? I need the "FOLDER" identifier.

Community
  • 1
  • 1
madsongr
  • 653
  • 1
  • 11
  • 29

0 Answers0