for me it works well for uploader.php as such:
<?php
require_once("backend/functions.php");
dbconn(false);
loggedinonly();
stdhead("File Uploader");
if (!$CURUSER || $CURUSER["class"]<"3"){
show_error_msg(T_("ERROR"), T_("SORRY_NO_RIGHTS_TO_ACCESS"), 1);
}
begin_frame("Partage De Fichier");
if ($CURUSER["class"] >= 3 && $CURUSER["class"]) {
$maxFileSize = 100 * 1024 * 1024; // This sets $maxFileSize to 100 MB. CHANGE THE 100 IF YOU WANT A NEW VALUE. Also Edit fileUploadScript using the same value
$maxFileSizeMB = $maxFileSize / (1024 * 1024); // Convert bytes to megabytes. DON"T TOUCH THIS!
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" http-equiv="refresh" content="100" border="none">
<link rel="stylesheet" type="text/css" href="<?php echo $site_config['SITEURL'];?>/themes/<?php echo $THEME;?>/themes.css" />
<title>Téléchargement de fichier</title>
<script>
function validateFile() {
const fileInput = document.getElementById("fileToUpload");
const fileSize = fileInput.files[0].size; // file size in bytes
const maxFileSizeMB = <?php echo $maxFileSizeMB; ?>;
const maxFileSizeBytes = maxFileSizeMB * 1024 * 1024; // convert to bytes
if (fileSize > maxFileSizeBytes) {
const fileSizeMB = Math.round(fileSize / (1024 * 1024));
alert("File is too large. Maximum file size is " + maxFileSizeMB + " MB. Your file size is " + fileSizeMB + " MB.");
return false; // prevent form submission
}
return true; // allow form submission
}
</script>
</head>
<body>
<br/>
<table border="0" cellpadding="3" class="table_table" width="55%" align="center"><tr>
<td class="table_col1" align="center">
<form action="fileUploadScript.php" method="post" enctype="multipart/form-data" onsubmit="return validateFile()">
Partager Le Fichier:
<input type="file" name="the_file" id="fileToUpload">
<input type="submit" name="submit" value="Start Upload"><hr/><center>
<?php
$maxFileSizeMB = 100; // 100 MB
$maxFileSizeBytes = $maxFileSizeMB * 1024 * 1024; // convert to bytes
$fileExtensionsAllowed = ['jpeg','jpg','png','gif','ico','pdf','psd','rar','zip','php','txt']; // These will be the only file extensions allowed. Add/Remove as needed
echo "<p>Taille de fichier maximale : " . $maxFileSizeMB . " MB</p>";
echo "<p>Types autorisés: " . implode(', ', $fileExtensionsAllowed) . "</p>";
?></center>
</form>
</td></tr></table>
</body>
</html>
<?php
$uploadDirectory = "/uploadedfiles/"; // Create this directory in your root. chmod 775
function formatBytes($bytes, $decimals = 2) {
$size = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); // Overkill amounts of conversion, but thorough
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . @$size[$factor];
}
// Scan the upload directory for files
$files = scandir($_SERVER['DOCUMENT_ROOT'] . $uploadDirectory);
// Remove "." and ".." from the list of files
$files = array_diff($files, array('.', '..'));
// Display a list of all files found
echo '<br/><center><color="red">⚞ Les Fichiers Disponible ⚟</color></center><hr/>';
if (count($files) > 0):
?>
<table cellpadding="5" class="table_table" width="85%" align="center">
<tr>
<th class="table_head">Supp.</th>
<th class="table_head">Taille</th>
<th class="table_head">Nom Du Fichier / Téléchargement</th>
</tr>
<tr>
<?php foreach ($files as $file): ?>
<?php if (get_user_class() >= 3): ?>
<form action="fileDeleteScript.php" method="post" style="display: inline-block;" onsubmit="return confirm('Êtes-vous sûr de vouloir supprimer ce fichier?');">
<td class="table_col2" align="center"><input type="hidden" name="fileToDelete" value="<?= $file ?>"><button type="submit" name="delete" class="stylebouton" >Supprimer</button></td>
</form>
<td class="table_col1" align="center">
<?php endif; ?>
<?php if (is_file($_SERVER['DOCUMENT_ROOT'] . $uploadDirectory . $file)): ?>
<span style="font-size: 13px;">(<?= formatBytes(filesize($_SERVER['DOCUMENT_ROOT'] . $uploadDirectory . $file)) ?>)</span></td>
<td class="table_col2" align="center" width="75%"><?php endif; ?>
<a href="<?= $uploadDirectory . $file ?>" class="download-link"><?= $file ?></a></td>
</tr>
<?php endforeach; ?>
</table>
<?php else: ?>
<p><i>..Aucun fichier trouvé!</i></p>
<?php endif; ?>
<br/>
<?php } ?>
<?php
end_frame();
stdfoot();
?>
If it can help! ;)
Last edited by spiritblue on 2023-02-27 22:11:45