Skip to content
Snippets Groups Projects
Commit f848f00c authored by nandXor's avatar nandXor
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
FROM php:8.1-apache
COPY src/ /var/www/html/
RUN mkdir -p /var/www/html/audio
RUN chown -R www-data:www-data *
ADD ./docker/custom-php.ini /usr/local/etc/php/conf.d/custom-php.ini
\ No newline at end of file
version: "3.9"
services:
audio_server:
build: .
ports:
- "80:80"
volumes:
- audio_files:/var/lib/mysql/data
volumes:
audio_files:
\ No newline at end of file
[php]
upload_max_filesize=64M
post_max_size=64M
max_execution_time=100
memory_limit=128M
\ No newline at end of file
# Fridge Audioserver
```
http://ip-adresse/ - Fridge Audiomanagement (upload and delete files)
http://ip-adresse/audio.php - Redirect to random .mp3 file
```
\ No newline at end of file
<?php
include('global.php');
// Get Random File
$files_count = count($files);
if($files_count == 0) {
die("Error: No valid '" . $TYPE . "' files found.");
}
$random_number = rand(0, $files_count - 1);
$random_file = $DIR . '/' . $files[$random_number];
// Redirect
header("Location: " . $random_file);
die();
?>
\ No newline at end of file
<?php
include('global.php');
if (isset($_POST['delete'])) {
// Name der löschenden Datei
$target_file = $DIR . '/' . basename($_POST["filename"]);
// Überprüfen, ob die Datei bereits existiert
if (file_exists($target_file)) {
unlink($target_file);
} else {
echo "Die Datei existiert nicht.";
}
}
header("Location: /");
?>
\ No newline at end of file
<?php
// Change me if you want to
$DIR = 'audio';
$TYPE = '.mp3';
$files = scandir($DIR);
// Check Type
foreach ($files as $key => $file) {
if (substr($file, -1 * strlen($TYPE)) != $TYPE) {
unset($files[$key]);
}
}
$files = array_values($files);
?>
\ No newline at end of file
<?php
include('global.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Fridge Audiomanagement</title>
<style>
body {
background-color: #222;
color: #fff;
font-family: Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
margin: 0;
padding: 0;
}
h1 {
font-size: 2em;
text-align: center;
}
table {
border-collapse: collapse;
margin: 20px auto;
width: 80%;
}
th,
td {
border: 1px solid #fff;
padding: 10px;
text-align: left;
}
th {
background-color: #444;
}
td a {
color: #fff;
text-decoration: none;
}
td a:hover {
text-decoration: underline;
}
.button {
background-color: #444;
border: none;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 1em;
margin: 0 5px;
padding: 10px 20px;
text-align: center;
text-decoration: none;
}
.button:hover {
background-color: #666;
}
#upload-form {
margin: 20px auto;
text-align: center;
width: 80%;
}
input[type="file"] {
display: none;
}
label[for="file-upload"] {
background-color: #444;
border: none;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 1em;
margin: 0 5px;
padding: 7.5px 20px;
text-align: center;
text-decoration: none;
}
label[for="file-upload"]:hover {
background-color: #666;
}
input[type="submit"],
button {
background-color: #444;
border: none;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 1em;
margin: 0 5px;
padding: 10px 20px;
text-align: center;
text-decoration: none;
}
input[type="submit"]:hover,
button:hover {
background-color: #666;
}
</style>
</head>
<body>
<h1>Fridge Audiomanagement</h1>
<table>
<thead>
<tr>
<th>File Name</th>
<th style="width: 2%">Action</th>
</tr>
</thead>
<tbody>
<?php
if (count($files) > 0) {
foreach ($files as $file) {
?>
<tr>
<td><a href="/<?php echo $DIR . '/' . $file ?>"><?php echo $file ?></a></td>
<td>
<form method="POST" action="/delete.php">
<input type="hidden" name="filename" value="<?php echo $file ?>">
<button class="button" type="submit" name="delete" value="1">Delete</button>
</form>
</td>
</tr>
<?php
}
} else { ?>
<tr>
<td colspan="2">No files uploaded yet</td>
</tr>
<?php } ?>
</tbody>
</table>
<form action="/upload.php" id="upload-form" method="POST" enctype="multipart/form-data">
<label for="file-upload" id="file-upload-label">Select file</label>
<input type="file" name="file" id="file-upload" accept="<?php echo $TYPE ?>" onchange="input()">
<button type="submit" name="upload">
Upload</button>
</form>
</body>
<script>
function input() {
let fileName = document.getElementById('file-upload').files[0].name;
document.getElementById('file-upload-label').innerHTML = fileName;
}
</script>
</html>
\ No newline at end of file
<?php
include('global.php');
if (isset($_POST['upload'])) {
// Name der hochgeladenen Datei
$target_file = $DIR . '/' . basename($_FILES["file"]["name"]);
// Überprüfen, ob die Datei bereits existiert
if (file_exists($target_file)) {
echo "Die Datei existiert bereits.";
} else {
// Versuche, die Datei hochzuladen
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
header("Location: /");
} else {
echo "Beim Hochladen der Datei ist ein Fehler aufgetreten.";
}
}
} else {
header("Location: /");
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment