I would like to do a multi upload with various img formats, I am researching how it does using php 7.1, I understood more or less the business logic. I just can not reproduce.
Can anyone give me a hand or link with a correct multi-upload application reference with various file formats
== 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>