324 lines
9.5 KiB
PHP
324 lines
9.5 KiB
PHP
<?php
|
|
require('../.hta_config/env.php');
|
|
require('../.hta_header.php');
|
|
require('../.hta_admin_header.php');
|
|
$current_date_time = date("Y-m-d H:i:s");
|
|
$home_uri_for_file_link = $_SERVER['HTTP_HOST'];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) {
|
|
$target_dir = $_SERVER['DOCUMENT_ROOT'] . "/assets/uploaded-file/"; // Full path to assets folder
|
|
$desc_txt = $_POST['desc_txt']; // ALT text
|
|
$file_name = $_FILES['file']['name']; // Original file name
|
|
$file_tmp = $_FILES['file']['tmp_name']; // Temporary file path
|
|
|
|
if (file_exists($file_tmp)) {
|
|
$mimeType = mime_content_type($file_tmp); // Get the mime type of the file
|
|
if (!file_exists($target_dir)) {
|
|
mkdir($target_dir, 0777, true); // Create the directory if it doesn't exist
|
|
}
|
|
$target_file = $target_dir . basename($file_name);
|
|
if (move_uploaded_file($file_tmp, $target_file)) {
|
|
$file_url = "/assets/uploaded-file/" . basename($file_name); // URL of the uploaded file
|
|
try {
|
|
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
$stmt = $conn->prepare("INSERT INTO scc_files (link, alt, file_name) VALUES (:link, :alt, :file_name)");
|
|
$stmt->bindParam(':link', $file_url);
|
|
$stmt->bindParam(':alt', $desc_txt);
|
|
$stmt->bindParam(':file_name', $file_name);
|
|
$stmt->execute();
|
|
echo "File uploaded and record saved successfully.";
|
|
} catch (PDOException $e) {
|
|
echo "Database Error: " . $e->getMessage();
|
|
}
|
|
} else {
|
|
echo "Error: Could not move the uploaded file.";
|
|
}
|
|
} else {
|
|
echo "Error: Uploaded file is missing.";
|
|
}
|
|
} else {
|
|
switch ($_FILES['file']['error']) {
|
|
case UPLOAD_ERR_NO_FILE:
|
|
echo "No file was uploaded.";
|
|
break;
|
|
default:
|
|
echo "Unknown error occurred during file upload.";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
<form method="post" enctype="multipart/form-data">
|
|
<div class="upload-container">
|
|
<p class="title">Files List & Add New Files</p>
|
|
<div class="file-upload-section">
|
|
<div class="upload-icon">
|
|
<label for="file" class="file-label">
|
|
<img src="/assets/upload.svg" alt="Upload" />
|
|
<input type="file" name="file" id="file" hidden />
|
|
</label>
|
|
</div>
|
|
<div class="input-section">
|
|
<div class="file-details">
|
|
<div id="file-name-show-section" class="file-name-section">
|
|
<span id="fileName">No file selected</span>
|
|
<button type="button" onclick="removeFile()" class="remove-file-btn">×</button>
|
|
</div>
|
|
<label for="desc_txt" class="input-label">ALT Text:</label>
|
|
<input type="text" name="desc_txt" id="desc_txt" class="text-input" placeholder="Description (6 words max)" />
|
|
</div>
|
|
<input type="submit" name="upload_file" id="upload_file" value="Upload" class="submit-btn" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="table-container">
|
|
<table class="responsive-table">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>File Link</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
|
|
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
$stmt = $conn->prepare("SELECT * FROM `scc_files` ORDER BY id DESC ");
|
|
$stmt->execute();
|
|
$content = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
foreach($content as $pageData){ ?>
|
|
<tr>
|
|
<td><?php echo $pageData['id']; ?></td>
|
|
<td><?php echo $pageData['link']; ?></td>
|
|
<td>
|
|
<div class="action-container">
|
|
<button onclick="copyToClipboard('<?php echo $pageData['link']; ?>', this)" class="action-btn">Copy</button>
|
|
<span class="copied-msg">Copied!</span>
|
|
<a href="<?php echo $home_uri_for_file_link . $pageData['link']; ?>" target="_blank" class="action-btn">View</a>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php } ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<script>
|
|
// Copy to Clipboard
|
|
function copyToClipboard(text, button) {
|
|
var input = document.createElement('textarea');
|
|
input.value = text;
|
|
document.body.appendChild(input);
|
|
input.select();
|
|
document.execCommand('copy');
|
|
document.body.removeChild(input);
|
|
|
|
// Show 'Copied!' message and hide the button temporarily
|
|
var actionContainer = button.parentNode;
|
|
var copiedMsg = actionContainer.querySelector('.copied-msg');
|
|
copiedMsg.style.display = 'inline';
|
|
button.style.display = 'none';
|
|
|
|
// Hide the 'Copied!' message after 1 second
|
|
setTimeout(function () {
|
|
copiedMsg.style.display = 'none';
|
|
button.style.display = 'inline';
|
|
}, 1000);
|
|
}
|
|
|
|
// Show File Selection
|
|
document.getElementById('file').addEventListener('change', function (event) {
|
|
const file = event.target.files[0];
|
|
const fileNameSection = document.getElementById('file-name-show-section');
|
|
const fileNameSpan = document.getElementById('fileName');
|
|
|
|
if (file) {
|
|
fileNameSection.style.display = 'flex';
|
|
fileNameSpan.textContent = 'File Selected: ' + file.name;
|
|
} else {
|
|
fileNameSection.style.display = 'none';
|
|
fileNameSpan.textContent = 'No file selected';
|
|
}
|
|
});
|
|
|
|
// Remove File
|
|
function removeFile() {
|
|
const fileInput = document.getElementById('file');
|
|
const fileNameSection = document.getElementById('file-name-show-section');
|
|
const fileNameSpan = document.getElementById('fileName');
|
|
|
|
fileInput.value = '';
|
|
fileNameSection.style.display = 'none';
|
|
fileNameSpan.textContent = 'No file selected';
|
|
}
|
|
|
|
|
|
</script>
|
|
<style>
|
|
/* General Styles */
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.upload-container, .table-container {
|
|
margin: 20px auto;
|
|
width: 90%;
|
|
max-width: 800px;
|
|
}
|
|
|
|
.title {
|
|
font-size: 24px;
|
|
text-align: center;
|
|
margin-bottom: 20px;
|
|
color: #402517;
|
|
}
|
|
|
|
/* Upload Section */
|
|
.file-upload-section {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
/* gap: 20px; */
|
|
border: 2px dashed #402517;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
justify-content: center;
|
|
align-items: center;
|
|
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.upload-icon {
|
|
text-align: center;
|
|
}
|
|
|
|
.file-label {
|
|
background: #402517;
|
|
padding: 20px;
|
|
border-radius: 50%;
|
|
display: inline-block;
|
|
cursor: pointer;
|
|
transition: transform 0.3s ease;
|
|
}
|
|
.input-section {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
width: 100%;
|
|
}
|
|
|
|
.text-input {
|
|
border: 2px solid #7a7a7a;
|
|
padding: 7px;
|
|
border-radius: 5px;
|
|
width: 100%;
|
|
}
|
|
|
|
.submit-btn {
|
|
background-color: #402517;
|
|
color: #fff;
|
|
padding: 7px;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s ease;
|
|
outline: none;
|
|
}
|
|
.file-name-section {
|
|
display: none; /* Initially hidden */
|
|
gap: 10px;
|
|
align-items: center;
|
|
}
|
|
|
|
.remove-file-btn {
|
|
background-color: #402517;
|
|
color: #fff;
|
|
cursor: pointer;
|
|
border: none;
|
|
outline: none;
|
|
border-radius: 50%;
|
|
padding: 0 7px;
|
|
}
|
|
|
|
.remove-file-btn:hover {
|
|
background-color: #5c3d27;
|
|
}
|
|
.copied-msg {
|
|
display: none; /* Initially hidden */
|
|
background-color: #402517;
|
|
color: #fff;
|
|
border-radius: 6px;
|
|
padding: 6px 12px;
|
|
margin-left: 10px;
|
|
}
|
|
|
|
/* Table Section */
|
|
.table-container {
|
|
overflow-x: auto;
|
|
/* margin-top: 20px; */
|
|
}
|
|
|
|
.responsive-table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin: 0 auto;
|
|
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.responsive-table th, .responsive-table td {
|
|
border: 2px solid #7a7a7a;
|
|
padding: 10px;
|
|
text-align: center;
|
|
}
|
|
|
|
.responsive-table th {
|
|
background-color: #402517;
|
|
color: #fff;
|
|
}
|
|
|
|
.action-container {
|
|
display: flex;
|
|
gap: 10px;
|
|
justify-content: center;
|
|
}
|
|
|
|
.action-btn {
|
|
background-color: #402517;
|
|
color: #fff;
|
|
padding: 8px 12px;
|
|
border-radius: 5px;
|
|
text-decoration: none;
|
|
transition: background-color 0.3s ease;
|
|
outline: none;
|
|
border: none;
|
|
}
|
|
|
|
|
|
/* Responsive Design */
|
|
@media (max-width: 600px) {
|
|
.file-upload-section {
|
|
flex-direction: column;
|
|
}
|
|
|
|
.responsive-table {
|
|
font-size: 14px;
|
|
}
|
|
|
|
.action-btn {
|
|
font-size: 12px;
|
|
padding: 6px 8px;
|
|
}
|
|
}
|
|
|
|
|
|
</style>
|
|
<?php
|
|
require('../.hta_footer.php');
|
|
?>
|