我的应用程序的想法是,我应该获得一个字符串,该字符串带有指向对它们进行排序的图像的链接。我的问题是,当我使用INSERT时,它会给我$ result [“ message”] =“ error”。我还注意到,如果列表很小,那么INSERT可以工作,这很奇怪。
<?php
if ($_SERVER['REQUEST_METHOD'] =='POST'){
$ids = $_POST['ids'];
$time = $_POST['time'];
$itemS = $_POST['item'];
$typeS = $_POST['type'];
require_once 'connect.php';
$v = explode(',', $itemS);
$plan = explode(',', $typeS);
$ids_post = rand();
foreach ($plan as $key => $item) {
if (trim($item) == 'i') {
$rand = rand();
$path = "posts_image/$rand.jpeg";
$finalPath = "http://192.168.100.9/login/".$path;
if (file_put_contents($path, base64_decode($v[$key]))) {
$v[$key] = $finalPath;
} else {
$result["message"] = "error";
echo json_encode($result);
mysqli_close($conn);
}
}
if (trim($item) == 'ci') {
$rand = rand();
$path = "posts_image/$rand.jpeg";
$finalPath = "http://192.168.100.9/login/".$path;
if (file_put_contents($path, base64_decode($v[$key]))) {
$v[$key] = $finalPath;
} else {
$result["message"] = "error";
echo json_encode($result);
mysqli_close($conn);
}
}
}
$item = implode(',', $v);
$type = implode(',', $plan);
if (mysqli_query($conn, "INSERT INTO `new_post` (ids_post, ids, item, type, time_post ) VALUES ('$ids_post', '$ids', '$item', '$type', '$time')")) {
$result["message"] = "success";
echo json_encode($result);
mysqli_close($conn);
} else {
$result["message"] = "error";
echo json_encode($result);
mysqli_close($conn);
}
} else {
$result["message"] = "error";
echo json_encode($result);
mysqli_close($conn);
}