我正在处理 WordPress 上传元字段。当用户上传图像时,图像的大小是二维的,一个是“拇指”,一个是“大”,它们的大小非常完美。我使用不同的元键将两个图像维度路径保存在数据库中,例如:
对于拇指图像wpc_resize_thumb_images和大图像wpc_resize_big_images。
当我在数据库中保存图像路径时,它会完美保存。
这是我将它们保存在数据库中的代码:
对于大图像
$product_img_path[$count]['wpc_resize_big_img'] = $upload_dir['url'].'/'.$resize_img_name;
update_post_meta($post->ID, 'wpc_resize_big_images', $product_img_path);
在数据库中保存如下:
元密钥
wpc_resize_big_images
元值
a:2:{i:1;a:1:{s:18:"wpc_resize_big_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg";}i:2;a:1:{s:18:"wpc_resize_big_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg";}}
对于拇指图像
$product_img_path[$count]['wpc_resize_thumb_img'] = $upload_dir['url'].'/'.$resize_img_name;
update_post_meta($post->ID, 'wpc_resize_thumb_images', $product_img_path);
在数据库中保存如下:
元密钥
wpc_resize_thumb_images
元值
a:2:{i:1;a:1:{s:20:"wpc_resize_thumb_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212x159.jpg";}i:2;a:1:{s:20:"wpc_resize_thumb_img";s:79:"http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212x141.jpg";}}
当我打印它们时,它们会向我显示这样的结果:
大图像
$wpc_resize_big_images = get_post_meta($post->ID, 'wpc_resize_big_images', true);
echo "<pre>";
print_r($wpc_resize_big_images);
echo "</pre>";
结果是
Array
(
[1] => Array
(
[wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212x159.jpg
)
[2] => Array
(
[wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212x141.jpg
)
)
拇指图像
$wpc_resize_thumb_images = get_post_meta($post->ID, 'wpc_resize_thumb_images', true);
echo "<pre>";
print_r($wpc_resize_thumb_images);
echo "</pre>;
结果是
Array
(
[1] => Array
(
[wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
)
[2] => Array
(
[wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
)
)
现在我的问题是如何使用一个元键合并和保存数据库的两个维度,当我打印元键时,它会给我这样的结果
我要这个
Array
(
[1] => Array
(
[wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212x159.jpg
[wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500x375.jpg
)
[2] => Array
(
[wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212x141.jpg
[wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500x333.jpg
)
)