0
我試圖追加圖像引用到我的數據庫中的列image1-4,而不是我得到的圖像上傳每次x3次和隨機引用在phpmyadmin。PHP的「循環」上傳到數據庫
<?php
$user_name = "root";
$user_pass = "";
$host_name = "localhost";
$db_name = "melony";
$con = mysqli_connect($host_name, $user_name, $user_pass, $db_name);
if($con)
{
$image = $_POST['image'];
$name = $_POST['name'];
$lat = (float) $_POST['lat'];
$lng = (float) $_POST['lng'];
for($i=1; $i<5; $i=$i+1){
$now = DateTime::createFromFormat('U.u', microtime(true));
$id = $now->format('YmdHisu');
$upload_path = "uploads/$id.jpeg";
$sql = "insert into uploads(name,lat,lng,image,image2,image3,image4) values
('$name','$lat','$lng','$upload_path','a','a','a')ON DUPLICATE KEY UPDATE
image$i = '$upload_path'";
if(mysqli_query($con,$sql))
{
file_put_contents($upload_path,base64_decode($image));
echo json_encode(array('response'=>'Image Upload Successfully'));
}
else
{
echo json_encode(array('response'=>'Image upload failed1,
mysqli_error($con)'));
}
}
}
else
{
echo json_encode(array('response'=>'Image Upload Failed2'));
}
mysqli_close($con);
?>
爲什麼會出現在您的文章 –
填充空間這麼多ž由於需要代碼/描述比例 – Andri
您的插入應該在循環之後。爲每幅圖像收集循環中的信息,然後只進行一次插入。 –