0

let say i have this folder to store captcha image

$directory = "http://localhost/test/wp-content/plugins/test/captcha/";

i try alot of codes like opendir, glob() etc trying together my image file name from the directory above but fail.

image file name is captcha.jpeg.

i have no choice but to use static url as shown below. but my captcha will be generating images with random (name).jpeg that is why i need a dynamic way to get image file whereby *.jpeg

$directory="http://localhost/test/wpcontent/plugins/test/captcha/captcha.jpeg";

i wants to get the whole image url return as json. Please anyone have resource to help me thanks.

return array("image url" => $image_url);
xSea
  • 212
  • 5
  • 24

1 Answers1

5

Did you try it?

$path_parts = pathinfo('http://localhost/test/wpcontent/plugins/test/captcha/captcha.jpeg');

$returnArray = ['image url' => $path_parts['basename']];

return json_encode($returnArray);

It return:

{
    "image_url" : "captcha.jpeg"
}

Pathinfo() PHP Manual

SarDau Mort
  • 187
  • 4