我们致力于Web服务,我们希望将图像数据库保存在formate中 a:1:{i:0; s:1:“a.jpg,b.jpg,c.jpg”;}但我们的形象另存为 a:3:{i:0; s:7:“am1.jpg”; i:1; s:7:“am2.jpg”; i:2; s:7:“am3.jpg”;}。请帮帮我
我们的代码是:
<?php
include_once( 'connection.php');
$ data = file_get_contents('php:// input');
$ json = json_decode($ data);
$ target_path =“uploads /”;
$target_path1 = $target_path . basename($_FILES['image1']['name']);
$target_path2 = $target_path . basename($_FILES['image2']['name']);
$target_path3 = $target_path . basename($_FILES['image3']['name']);
$file_upload = move_uploaded_file($_FILES['image1']['tmp_name'], $target_path1);
$file_upload = move_uploaded_file($_FILES['image2']['tmp_name'], $target_path2);
$file_upload = move_uploaded_file($_FILES['image3']['tmp_name'], $target_path3);
$image = serialize(array($_FILES['image1']['name'], $_FILES['image2']['name'], $_FILES['image3']['name']));
$sql = "INSERT INTO `users` (`image`) VALUES ('$image')";
$qur = mysql_query($sql);
echo json_encode($ response);
&GT;
答案 0 :(得分:0)
$image = serialize(array($_FILES['image1']['name'] .','. $_FILES['image2']['name'] .','. $_FILES['image3']['name']));
或
$image = serialize(array(implode(',', array_column($_FILES,'name'))));
如果你想要的只是一个逗号分隔的字符串
,为什么还要打扰一个数组答案 1 :(得分:0)
您可以内爆图像名称,然后序列化字符串。
$image = serialize(implode(',', array($_FILES['image1']['name'], $_FILES['image2']['name'], $_FILES['image3']['name'])));
答案 2 :(得分:0)
您可以将所有字符串放在数组中:
grep
然后内爆:
man grep
为了达到你想要的目的,应该是:
$a = array();
$a[] = 'am1.jpg';
$a[] = 'am2.jpg';
$a[] = 'am3.jpg';