【问题标题】:How to get image file name in php [duplicate]如何在php中获取图像文件名[重复]
【发布时间】:2015-11-20 04:38:18
【问题描述】:

假设我有这个文件夹来存储验证码图像

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

我尝试了很多代码,如 opendir、glob() 等,尝试将上面目录中的图像文件名放在一起,但失败了。

图像文件名为 captcha.jpeg。

我别无选择,只能使用如下所示的静态 url。但是我的验证码将生成带有随机(名称).jpeg 的图像,这就是为什么我需要一种动态方式来获取图像文件,其中 *.jpeg

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

我想将整个图像 url 返回为 json。请任何有资源的人帮助我,谢谢。

return array("image url" => $image_url);

【问题讨论】:

  • 为什么不在创建时将图像名称保存在 session/cookie 中?

标签: php image url


【解决方案1】:

你试过了吗?

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

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

return json_encode($returnArray);

返回:

{
    "image_url" : "captcha.jpeg"
}

Pathinfo() PHP Manual

【讨论】:

    猜你喜欢
    • 2014-03-30
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-12
    • 1970-01-01
    相关资源
    最近更新 更多