我正在創建圖庫網站,並且希望僅使用PHP和MYSQLI創建一個多圖像上傳器...我不擅長編碼,因此本網站上的多圖像上傳的其他示例沒有不爲我工作。多圖像上傳
以下是根據當前用戶會話將數據發佈到數據庫中的工作代碼。
HTML:
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="image">Select a file:</label>
<input type="file" name="image[]" id="image" multiple='multiple' />
<br /><br>
<label for="picname">Title:</label>
<input type="text" name="picname" id="picname" />
<br /><br>
<label for="picdesc">Description:</label>
<input type="text" name="picdesc" id="picdesc" />
<br /><br>
<label for="piccat">Category:</label>
<select name="piccat" id="piccat">
<option value="--"></option>
<option value="animation">Animation</option>
<option value="illustration">Illustration</option>
<option value="photography">Photography</option>
</select>
<br /><br>
<input type="submit" name="submit" value="Submit" />
</form>
PHP &的mysqli:
<?php
$path = "images/projects/";
include("check.php");
if (isset($_POST["submit"])) {
$image = $_FILES["image"]["tmp_name"];
$imageName = $_FILES["image"]["name"];
$imageSize = $_FILES["image"]["size"];
$imageType = $_FILES["image"]["type"];
$imageTitle = $_POST["picname"];
$imageDescription = $_POST["picdesc"];
$imageCategory = $_POST["piccat"];
$len = count($image);
$path = $path . $imageName;
$query = $db -> prepare("INSERT INTO images (user_id, image, description, type, title, size, category)
VALUES (?, ?, ?, ?, ?, ?, ?)");
$query -> bind_param('issssis', $_SESSION['user_id'], $imageName, $imageDescription, $imageType, $imageTitle, $imageSize, $imageCategory);
$query -> execute();
$query -> close();
if ($imageName){
move_uploaded_file($image, $path);
}
}
?>
它工作正常,但只能上傳一個圖片。如何選擇多個圖像並一次上傳所有圖像?
有一個真棒爲你正在嘗試做的。 https://github.com/samayo/bulletproof – Ikari
哦,謝謝你,但我在大學的課程這樣做,不幸的是,我們不允許使用任何第三方或類似的東西... – Elina
http:// stackoverflow .com/questions/24895170/multiple-image-upload-php-form-with-one-input,http://php.net/manual/en/features.file-upload.multiple.php –