front end upload & gallery page creation. Need to fix "Upload" button
This commit is contained in:
parent
ce71983d57
commit
9e388faeef
7 changed files with 221 additions and 9 deletions
20
frontend/css/gallery.css
Normal file
20
frontend/css/gallery.css
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* Gallery Page Styles */
|
||||
#gallery-container {
|
||||
width: 100%;
|
||||
max-width: 1200px;
|
||||
padding: 20px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
#image-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
grid-gap: 20px;
|
||||
}
|
||||
|
||||
#image-grid img {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
87
frontend/css/styles.css
Normal file
87
frontend/css/styles.css
Normal file
|
@ -0,0 +1,87 @@
|
|||
/* Navigation Bar Styles */
|
||||
nav {
|
||||
background-color: #333;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.nav-container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 20px;
|
||||
}
|
||||
|
||||
.nav-logo {
|
||||
color: white;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.nav-menu {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.nav-menu li {
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.nav-menu a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
padding: 10px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.nav-menu a:hover,
|
||||
.nav-menu a.active {
|
||||
background-color: #555;
|
||||
}
|
||||
|
||||
/* Home Page Styles */
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
background-color: #f1f1f1;
|
||||
padding-top: 80px; /* Add padding to accommodate the navigation bar */
|
||||
}
|
||||
|
||||
#drag-drop-container {
|
||||
border: 2px dashed #ccc;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
width: 400px;
|
||||
background-color: white;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
#drag-drop-container.drag-over {
|
||||
border-color: #4CAF50;
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #45a049;
|
||||
}
|
32
frontend/gallery/gallery.html
Normal file
32
frontend/gallery/gallery.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Image Gallery</title>
|
||||
<link rel="stylesheet" href="../css/styles.css">
|
||||
<link rel="stylesheet" href="../css/gallery.css">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Navigation Bar -->
|
||||
<nav>
|
||||
<div class="nav-container">
|
||||
<a href="../index.html" class="nav-logo">Image Upload</a>
|
||||
<ul class="nav-menu">
|
||||
<li><a href="../index.html">Home</a></li>
|
||||
<li><a href="gallery.html" class="active">Gallery</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Gallery Page -->
|
||||
<div id="gallery-container">
|
||||
<h2>Image Gallery</h2>
|
||||
<div id="image-grid">
|
||||
<!-- Dynamically generated images will be displayed here -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="gallery.js"></script>
|
||||
</body>
|
||||
</html>
|
19
frontend/gallery/gallery.js
Normal file
19
frontend/gallery/gallery.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
// gallery.js
|
||||
|
||||
// Fetch the list of uploaded images from the server
|
||||
fetch('get_uploaded_images.php')
|
||||
.then(response => response.json())
|
||||
.then(images => {
|
||||
const imageGrid = document.getElementById('image-grid');
|
||||
|
||||
// Generate HTML elements for each image
|
||||
images.forEach(image => {
|
||||
const imageElement = document.createElement('img');
|
||||
imageElement.src = `uploads/${image}`;
|
||||
imageElement.alt = image;
|
||||
imageGrid.appendChild(imageElement);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching uploaded images:', error);
|
||||
});
|
|
@ -1,11 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>My App</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello, world!</h1>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Drag and Drop Image Upload</title>
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Navigation Bar -->
|
||||
<nav>
|
||||
<div class="nav-container">
|
||||
<a href="index.html" class="nav-logo">Image Upload</a>
|
||||
<ul class="nav-menu">
|
||||
<li><a href="index.html" class="active">Home</a></li>
|
||||
<li><a href="gallery/gallery.html">Gallery</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- Home Page (Upload) -->
|
||||
<div id="drag-drop-container">
|
||||
<h2>Drag and Drop Images</h2>
|
||||
<p>Drop your PNG or JPEG files here</p>
|
||||
<form id="upload-form" action="upload.php" method="POST" enctype="multipart/form-data">
|
||||
<input type="file" id="file-input" name="file" accept="image/png, image/jpeg" hidden>
|
||||
<button type="submit">Upload</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
32
frontend/script.js
Normal file
32
frontend/script.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const dragDropContainer = document.getElementById('drag-drop-container');
|
||||
const fileInput = document.getElementById('file-input');
|
||||
const uploadForm = document.getElementById('upload-form');
|
||||
|
||||
dragDropContainer.addEventListener('dragover', (event) => {
|
||||
event.preventDefault();
|
||||
dragDropContainer.classList.add('drag-over');
|
||||
});
|
||||
|
||||
dragDropContainer.addEventListener('dragleave', () => {
|
||||
dragDropContainer.classList.remove('drag-over');
|
||||
});
|
||||
|
||||
dragDropContainer.addEventListener('drop', (event) => {
|
||||
event.preventDefault();
|
||||
dragDropContainer.classList.remove('drag-over');
|
||||
|
||||
// Get the first file from the dropped files
|
||||
const file = event.dataTransfer.files[0];
|
||||
|
||||
// Check if the file is a PNG or JPEG
|
||||
if (file.type === 'image/png' || file.type === 'image/jpeg') {
|
||||
fileInput.files = event.dataTransfer.files;
|
||||
uploadForm.submit();
|
||||
} else {
|
||||
alert('Please drop a PNG or JPEG file.');
|
||||
}
|
||||
});
|
||||
|
||||
dragDropContainer.addEventListener('click', () => {
|
||||
fileInput.click();
|
||||
});
|
Loading…
Reference in a new issue