Gostaria de fazer um multi upload com variados formatos de img, estou pesquisando como faz usando php 7.1, entendi mais o menos a logica do negocio. só que nao estou conseguindo reproduzir.
Alguem poderia me dar uma mao ou link com uma referencia correta da aplicação de multi upload com variados formatos de arquivo
== index.php
<body>
<h3>Photo Gallery</h3>
<form action="add-album.php" method="post">
<label>Add New Album</label>
<input type="text" name="album_name">
<input type="submit" name="submit_album" value="Add">
</form>
<?php
if(isset($_GET['add_album_action'])){
if ($_GET['add_album_action'] == "sucessfull") { ?>
<br>New Album created <br><br>
<?php }
}
?>
<?php
$albums = $mysqli->query("SELECT * FROM gallery_albums");
while ($album_data = $albums->fetch_assoc()) {
$photos = $mysqli->query("SELECT * FROM gallery_photos WHERE album_id = ".$album_data['album_id']."");?>
<b>#<?php echo $album_data['album_id'] ?></b> <a href="view-album.php?album_id=<?php echo $album_data['album_id'] ?>"><?php echo $album_data['album_name'] ?></a> (<?php echo $photos->num_rows; ?>)<br><br>
<?php }
?>
</body>
upload_photo.php
<?php
include 'connection.php';
$album_id = $_GET['album_id'];
if ($_FILES['photo']['name'] != null) {
move_uploaded_file($_FILES['photo']['tmp_name'], "images/". $_FILES['photo']['name']);
$photo_link = "images/". $_FILES['photo']['name'];
$upload_photo = $mysqli->query("INSERT INTO gallery_photos (album_id, photo_link) VALUES ($album_id, '$photo_link')");
if ($upload_photo) {
header("Location: view-album.php?album_id=$album_id&upload_action=success");
} else {
echo $mysqli->error;
}
} else {
header("Location: index.php");
}
?>;
<?php
include 'connection.php';
if (isset($_GET['album_id'])) {
$album_id = $_GET['album_id'];
$get_album = $mysqli->query("SELECT * FROM gallery_albums WHERE album_id = $album_id");
$album_data = $get_album->fetch_assoc();
} else {
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php echo $album_data['album_name'] ?></title>
</head>
<body>
<?php
$photo_count = $mysqli->query("SELECT * FROM gallery_photos WHERE album_id = $album_id");
?>
<a href="index.php">Home</a> | <?php echo $album_data['album_name'] ?> (<?php echo $photo_count->num_rows; ?>)<br><br>
<form method="post" action="upload_photo.php?album_id=<?php echo $album_id ?>" enctype="multipart/form-data">
<label>Add photo to this album:</label><br>
<input type="file" name="photo" />
<input type="submit" name="upload_photo" value="Upload" />
</form>
<?php
if (isset($_GET['upload_action'])) {
if ($_GET['upload_action'] == "success") { ?>
<br><br>Photo successfully added to this album<br><br>
<?php }
}
?>
<?php
$photos = $mysqli->query("SELECT * FROM gallery_photos WHERE album_id = $album_id");
while($photo_data = $photos->fetch_assoc()) { ?>
<img src="<?php echo $photo_data['photo_link'] ?>" width="200px" height="200px" />
<?php }
?>
</body>
</html>
<form>
falta defnir oenctype="multipart/form-data"
e um elementoinput type="file"
. Por hora, o que pede está amplo. Há muitas coisas desde o upload e validação de tipos de arquivos. Pergunte uma coisa só.