-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (34 loc) · 1.21 KB
/
Copy pathscript.js
File metadata and controls
39 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const uploadBtn = document.getElementById('upload-btn');
const pdfUpload = document.getElementById('pdf-upload');
const pdfList = document.getElementById('pdf-list');
// Simulated admin check
const isAdmin = true; // Change this to false to simulate a regular user
// Simulated storage for uploaded PDFs
let uploadedPDFs = [];
// Function to handle PDF upload
uploadBtn.addEventListener('click', () => {
if (isAdmin) {
const file = pdfUpload.files[0];
if (file && file.type === 'application/pdf') {
const url = URL.createObjectURL(file);
uploadedPDFs.push({ name: file.name, url: url });
displayPDFs();
pdfUpload.value = ''; // Clear the input
} else {
alert('Please upload a valid PDF file.');
}
} else {
alert('Only admins can upload PDFs.');
}
});
// Function to display uploaded PDFs
function displayPDFs() {
pdfList.innerHTML = '';
uploadedPDFs.forEach(pdf => {
const li = document.createElement('li');
li.innerHTML = `<a href="${pdf.url}" target="_blank">${pdf.name}</a>`;
pdfList.appendChild(li);
});
}
// Initial display
displayPDFs();