200 lines
7.5 KiB
PHP
200 lines
7.5 KiB
PHP
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
.upload-container {
|
|
border: 2px dashed #ccc;
|
|
padding: 20px;
|
|
border-radius: 5px;
|
|
text-align: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
.progress-container {
|
|
margin-top: 20px;
|
|
padding: 10px;
|
|
border: 1px solid #eee;
|
|
border-radius: 5px;
|
|
display: none;
|
|
}
|
|
.progress-bar {
|
|
height: 20px;
|
|
background-color: #012402ff;
|
|
width: 0%;
|
|
border-radius: 5px;
|
|
transition: width 0.3s;
|
|
}
|
|
.progress-text {
|
|
margin-top: 10px;
|
|
}
|
|
#drop-area {
|
|
border: 2px dashed #ccc;
|
|
border-radius: 5px;
|
|
padding: 25px;
|
|
text-align: center;
|
|
cursor: pointer;
|
|
}
|
|
#drop-area.highlight {
|
|
border-color: #4CAF50;
|
|
background-color: #f0f9f0;
|
|
}
|
|
#content_3 {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
</style>
|
|
|
|
<h1>Video-Upload</h1>
|
|
|
|
<div class="upload-container">
|
|
<div id="drop-area">
|
|
<h2>Ziehen Sie die Datei hierher oder klicken Sie, um eine Datei auszuwählen</h2>
|
|
<input type="file" id="fileInput" style="display: none;">
|
|
</div>
|
|
<p>Die Datei wird automatisch in Teile aufgeteilt und hochgeladen</p>
|
|
</div>
|
|
|
|
<div class="progress-container" id="progressContainer">
|
|
<h3>Upload-Fortschritt</h3>
|
|
<div class="progress-bar" id="progressBar"></div>
|
|
<div class="progress-text" id="progress">Warten auf Upload...</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Generierung einer eindeutigen ID
|
|
function generateUUID() {
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
return v.toString(16);
|
|
});
|
|
}
|
|
|
|
// Haupt-DOM-Elemente
|
|
const dropArea = document.getElementById('drop-area');
|
|
const fileInput = document.getElementById('fileInput');
|
|
const progressContainer = document.getElementById('progressContainer');
|
|
const progressBar = document.getElementById('progressBar');
|
|
const progressText = document.getElementById('progress');
|
|
|
|
// Chunk-Größe in Bytes (25MB)
|
|
const chunkSize = 25 * 1024 * 1024;
|
|
|
|
// Verhindern des Standardverhaltens des Browsers beim Ziehen
|
|
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
|
dropArea.addEventListener(eventName, preventDefaults, false);
|
|
document.body.addEventListener(eventName, preventDefaults, false);
|
|
});
|
|
|
|
function preventDefaults(e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
}
|
|
|
|
// Hervorheben des Bereichs beim Ziehen
|
|
['dragenter', 'dragover'].forEach(eventName => {
|
|
dropArea.addEventListener(eventName, highlight, false);
|
|
});
|
|
|
|
['dragleave', 'drop'].forEach(eventName => {
|
|
dropArea.addEventListener(eventName, unhighlight, false);
|
|
});
|
|
|
|
function highlight() {
|
|
dropArea.classList.add('highlight');
|
|
}
|
|
|
|
function unhighlight() {
|
|
dropArea.classList.remove('highlight');
|
|
}
|
|
|
|
// Verarbeitung von Datei-Auswahl- und Zieh-Ereignissen
|
|
dropArea.addEventListener('drop', handleDrop, false);
|
|
dropArea.addEventListener('click', () => fileInput.click());
|
|
fileInput.addEventListener('change', handleFiles);
|
|
|
|
function handleDrop(e) {
|
|
const dt = e.dataTransfer;
|
|
const files = dt.files;
|
|
handleFiles({ target: { files } });
|
|
}
|
|
|
|
function handleFiles(e) {
|
|
const file = e.target.files[0];
|
|
if (file) {
|
|
uploadFile(file);
|
|
}
|
|
}
|
|
|
|
function uploadFile(file) {
|
|
const uuid = generateUUID();
|
|
const fileName = file.name;
|
|
const totalChunks = Math.ceil(file.size / chunkSize);
|
|
let uploadedChunks = 0;
|
|
|
|
progressContainer.style.display = 'block';
|
|
progressText.textContent = `Vorbereitung zum Hochladen...`;
|
|
|
|
// Funktion zum Hochladen eines Chunks
|
|
function uploadChunk(start) {
|
|
const end = Math.min(start + chunkSize, file.size);
|
|
const chunk = file.slice(start, end);
|
|
const chunkIndex = Math.floor(start / chunkSize);
|
|
|
|
const formData = new FormData();
|
|
formData.append('file', chunk);
|
|
formData.append('dzuuid', uuid);
|
|
formData.append('dzchunkindex', chunkIndex);
|
|
formData.append('dztotalchunkcount', totalChunks);
|
|
formData.append('dzdestinationfile', fileName);
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open('POST', 'https://intranet.awo-hamburg.de/mysyde/admin/video_uploud/video_uploud_server.php', true);
|
|
|
|
xhr.onload = function() {
|
|
if (xhr.status === 200) {
|
|
try {
|
|
const response = JSON.parse(xhr.responseText);
|
|
|
|
if (response.success) {
|
|
uploadedChunks++;
|
|
|
|
// Fortschritt aktualisieren
|
|
const progressPercent = Math.round((uploadedChunks / totalChunks) * 100);
|
|
progressBar.style.width = progressPercent + '%';
|
|
progressText.textContent = `Hochladen: ${progressPercent}% (Teil ${uploadedChunks}/${totalChunks})`;
|
|
|
|
// Wenn noch weitere Chunks hochgeladen werden müssen
|
|
if (start + chunkSize < file.size) {
|
|
uploadChunk(start + chunkSize);
|
|
} else if (uploadedChunks === totalChunks) {
|
|
// Alle Chunks hochgeladen
|
|
progressText.textContent = `Alle Teile hochgeladen, Verarbeitung auf dem Server...`;
|
|
|
|
if (response.file) {
|
|
progressText.textContent = `Datei "${response.file}" erfolgreich hochgeladen!`;
|
|
}
|
|
}
|
|
} else {
|
|
progressText.textContent = `Fehler: ${response.message || 'Unbekannter Fehler'}`;
|
|
}
|
|
} catch (e) {
|
|
progressText.textContent = `Fehler beim Parsen der Serverantwort: ${e.message}`;
|
|
}
|
|
} else {
|
|
progressText.textContent = `HTTP-Fehler: ${xhr.status}`;
|
|
}
|
|
};
|
|
|
|
xhr.onerror = function() {
|
|
progressText.textContent = `Netzwerkfehler beim Hochladen von Teil ${chunkIndex + 1}`;
|
|
};
|
|
|
|
xhr.send(formData);
|
|
}
|
|
|
|
// Beginnen Sie mit dem Hochladen des ersten Chunks
|
|
uploadChunk(0);
|
|
}
|
|
</script> |