如何导入多个图像? [英] How to import multiple image?

查看:28
本文介绍了如何导入多个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现场图像接受这种类型的多图像导入格式:

Field image is accepting this type of format for multiple image import:

a:10:{i:0;
      a:1:{s:6:"imgurl";s:71:"http://example.com/wp-content/uploads/2015/01/image.jpg";}
      i:1;
      a:1:{s:6:"imgurl";s:71:"http://example.com/wp-content/uploads/2015/01/image.jpg";}
     };

我试图找到一种方法来返回具有上述输出的 json_encode.在这个过程中,当我转换为数组格式时,我无法弄清楚 a:10:{}.

I am trying to find a way to return a json_encode with the above output. In the process I can't figure out a:10:{} when converted to array format.

$arr = array('a' => 10, // <-- I have a problem here what to use
           array( 'i' => 0, 'a' => 1, 
                          array('s' => [6, 'imgurl'], // <-- I have a problem here what to use
                                's' => (71,"http://example.com/wp-content/uploads/2015/01/image.jpg")
                               )
                         )
        );

我这样做对吗?

更新:

对不起,我不能尽快回复.因为我正在研究序列化和反序列化的工作原理.

Sorry I can't response sooner. Since I'm studying how serialize and unserialize works.

有点历史,我正在使用 WP All Import-Import XML/CSV WordPress 插件来导入 XML 数据.

A bit of history, I am using WP All Import- Import XML / CSV WordPress plugin to import XML data.

WP 自定义帖子类型 property 包含存储图像的字段名称 _property_slider_image.将 XML 容器标准拖放到该字段将不起作用.不工作,因为它没有链接每个属性下载的图像.

The WP custom post type property contain a field name _property_slider_image that store an image(s). Standard drag and drop of XML container to that field won't work. Not working as, it's not linking the downloaded images per property.

在检查 mysql 数据库后,该字段接受我上面提到的这种类型的合成器.老实说,我不知道它是什么.因为我只知道 json_encode 和 json_decode.这就是为什么我的帖子提到 json_encode.

After checking the mysql database the field accept this type of synthax I mention above. I honestly do not know what it is. Since I only know is json_encode and json_decode. That is why my post mention json_encode.

感谢 Kiyan.他给了我一个看哪里的提示.

Thanks to Kiyan. He gave me a hint where to look.

现在我不会手动将每个图像映射到每个属性记录.

Now I won't be manually mapping each image to each property record.

结果:

这是我经过一周研究后的输出.

Here's my output after a weeks of research.

function sl_output_property_slider(){
    $image_url_list = array(); 
    foreach (func_get_args() as $n) {
        // get image name
        $img_name = get_image_name($n);
        // add directory location with the following format
        // http://localhost/dev_slrealestate/wp-content/uploads/2015/01/1478_Image.jpeg
        $imgurl = 'http://localhost/dev_site/wp-content/uploads/'. date('Y') .'/'. date('m') . '/' . $img_name;
        array_push($image_url_list, array('imgurl'=>$imgurl));
    }

    $serialized_data = serialize($image_url_list);
    printf($serialized_data);
}

where function get_image_name($url) - 仅从原始 url 字符串返回图像名称.

where function get_image_name($url) - to return the image name only from original url string.

示例用法 - 短代码

[sl_output_property_slider({Images[1]/Image[1]/ImageURL[1]},
    {Images[1]/Image[2]/ImageURL[1]},{Images[1]/Image[3]/ImageURL[1]},
    {Images[1]/Image[4]/ImageURL[1]},{Images[1]/Image[5]/ImageURL[1]},
    {Images[1]/Image[6]/ImageURL[1]},{Images[1]/Image[7]/ImageURL[1]},
    {Images[1]/Image[8]/ImageURL[1]},{Images[1]/Image[9]/ImageURL[1]},
    {Images[1]/Image[10]/ImageURL[1]}
 )
]

推荐答案

这不是json字符串,必须使用反序列化函数

this is not a json string, you have to use unserialize function

http://php.net/manual/en/function.unserialize.php

这篇关于如何导入多个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆