我打算用MySQL作爲數據庫來製作一個使用PHP的圖像星系。PHP和MySQLi - 上傳多個圖像
我已經使用PHP做了多個上傳圖片,但是我遇到了問題。當我上傳8圖像在數據庫中只顯示1行數據。但在文件夾中有8張圖片我已上傳。
這裏是我的代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="a.php" method="post" enctype="multipart/form-data">
<input type="file" name="file_img[]" multiple>
<input type="submit" name="btn_upload" value="Upload">
</form>
<?php
include_once 'koneksi.php';
if(isset($_POST['btn_upload']))
{
for($i = 0; $i < count($_FILES['file_img']['name']); $i++)
{
$filetmp = $_FILES["file_img"]["tmp_name"][$i];
$filename = $_FILES["file_img"]["name"][$i];
$filetype = $_FILES["file_img"]["type"][$i];
$filepath = "uploads/".$filename;
move_uploaded_file($filetmp,$filepath);
$sql = "INSERT INTO files (file,path,type) VALUES ('$filename','$filepath','$filetype')";
if($connect->query($sql) === TRUE) {
header("Location: a.php");
} else {
header("Location: a.php");
}
}
$connect->close();}
?>
</body>
</html>
有人能幫助我嗎?感謝您的反饋:)
向我們展示您的數據庫結構'SHOW CREATE TABLE files' – Martin
和'var_dump($ _ FILES)'給你什麼?這個輸出是你期望的嗎? – Martin
你有沒有任何PHP錯誤? – Martin