我想添加多個圖片到網頁,但它只允許我添加1.我試圖添加超過3個圖像到網頁上,所有ive完成是添加一個按鈕,可以讓你選擇文件,但我想更多的1檔和4張圖片最低要上傳 繼承人的代碼:試圖將多個圖片添加到網頁上php
<section class="left">
<ul>
<li><a href="manufacturers.php">Manufacturers</a></li>
<li><a href="bikes.php">Bikes</a></li>
</ul>
</section>
<section class="right">
<?php
if (isset($_POST['submit'])) {
$stmt = $pdo->prepare('INSERT INTO bikes (model, description, price, manufacturerId)
VALUES (:model, :description, :price, :manufacturerId)');
$criteria = [
'model' => $_POST['model'],
'description' => $_POST['description'],
'price' => $_POST['price'],
'manufacturerId' => $_POST['manufacturerId']
];
$stmt->execute($criteria);
if ($_FILES['image']['error'] == 0) {
$fileName = $pdo->lastInsertId() . '.jpg';
move_uploaded_file($_FILES['image']['tmp_name'], '../images/bikes/' . $fileName);
}
echo 'Bike added';
}
else {
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
?>
<h2>Add Product</h2>
<form action="addbike.php" method="POST" enctype="multipart/form-data">
<label>Bike Model</label>
<input type="text" name="model" />
<label>Description</label>
<textarea name="description"></textarea>
<label>Condition</label>
<input type="text" name="Condition" />
<label>Price</label>
<input type="text" name="price" />
<label>Category</label>
<select name="manufacturerId">
<?php
$stmt = $pdo->prepare('SELECT * FROM manufacturers');
$stmt->execute();
foreach ($stmt as $row) {
echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
}
?>
</select>
<label>Bike image</label>
<input type="file" name="image" />
<input type="submit" name="submit" value="Add Product" />
</form>
<?php
}
else {
?>
<h2>Log in</h2>
<form action="index.php" method="post">
<label>Username</label>
<input type="text" name="username" />
<label>Password</label>
<input type="password" name="password" />
<input type="submit" name="submit" value="Log In" />
</form>
<?php
}
}
?>
圖像名稱應該是一個數組也可以使用jquery –
你必須使用文件名陣列和添加'multiple'屬性到文件輸入標籤 'input type =「file」name =「image []」multiple />' –
added 但是當我離開管理員頁面圖像不可見 – Pactz