【问题标题】:Php script to get url of all the images in directory in json stringphp脚本以json字符串获取目录中所有图像的url
【发布时间】:2016-07-23 14:04:57
【问题描述】:

我已经构建了一个 android 应用程序,当它调用包含所有图像 url 的 json 文件时显示来自服务器的图像。

所以我想要一个 php 脚本来搜索特定目录中的所有图像,然后将所有图像的 url 放入 json 格式。

我的域名http://arture.16mb.com

我的图片目录http://arture.16mb.com/images/

我目前使用的json格式

[{ “名称”:“死侍”,
“网址”:{
"小": "xyzdomain/images/1.jpg",
“中”:“xyzdomain/images/1.jpg”,
“大”:“xyzdomain/images/1.jpg” },
“时间戳”:“2016 年 2 月 12 日”
},
{
“名称”:“蝙蝠侠大战超人”,
“网址”:{
"小": "xyzdomain/images/1.jpg",
“中”:“xyzdomain/images/1.jpg”,
“大”:“xyzdomain/images/1.jpg”
},
“时间戳”:“2016 年 3 月 25 日”
}]

我希望我的 php 脚本制作的 json 格式

“图像”:{ "url": "//mydomain/images/....jpeg"
},
{
"url": "//mydomain/images/....jpeg"
},
{
"url": "//mydomain/images/....jpeg"
}

【问题讨论】:

  • 图片是否在同一服务器中,您的 php 脚本将在其中?
  • 是的,所有东西都会有一个服务器
  • 编辑您的问题并提供您想要的 json 结构、图像目录和访问图像的服务器域

标签: php android json http


【解决方案1】:

你可以试试这个:

$json = "";

foreach (glob('images/*.png') as $file){

    $json .= '{ "url":"//mydomain/'.$file.'" }, ';
}

$json = trim($json, ", ");

它的作用是获取所有带有.png扩展名的文件,如果你想要jpeg文件,你可以使用*.jpeg 然后,所有文件名都附加到$json

【讨论】:

猜你喜欢
  • 2012-08-01
  • 2010-12-03
  • 1970-01-01
  • 1970-01-01
  • 2012-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-20
相关资源
最近更新 更多