我可以使用我的代码一次上传一张图片,但是我添加了多个="多个"它让我突出显示要上传的多个图像,但只有一个图像上传到sql数据库。
以下是我的表格 -
<form action="upload_image.php" method="post" enctype="multipart/form-data">
<p>Select files:<br /><input type="file" name="image[]" multiple="multiple"/></p>
<p>
Choose an album<br />
<select name="album_id">
<?php
foreach ($albums as $album) {
echo '<option value="', $album['id'], '">', $album['name'], '</option>';
}
?>
</select>
</p>
<p><input type="submit" value="Upload" /></p>
</form>
我的PHP端看起来像这样 -
<?php
if (isset($_FILES['image'], $_POST['album_id'])) {
$image_name = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_temp = $_FILES['image']['tmp_name'];
$image_dimension = $_FILES['image']['dimension'];
$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
$image_ext = strtolower(end(explode('.', $image_name)));
$album_id = $_POST['album_id'];
$errors = array();
if (empty($image_name) || empty($album_id)) {
$errors[] = 'Something is missing';
} else {
if (in_array($image_ext, $allowed_ext) === false) {
$errors[] = 'File type not allowed';
}
if($image_size > 10485760){
$errors[] = 'Maximum file size is 10MB';
}
if (album_check($album_id) === false) {
$errors[] = 'Couldn\'t upload to that album';
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br />';
}
} else {
upload_image($image_temp, $image_ext, $album_id);
header('Location: view_album.php?album_id='.$album_id);
exit();
}
}
对此的任何帮助都会很棒!
此致 亚伦