I have been looking for a solution to a problem I'm having with my code. The nearest solution to my problem was found here however that solution didn't fit my problem.
I'm listing uploaded files in PHP on my page, with each file being an to the file's location. That works fine, however I am new to PHP and am having difficulty in implementing others code.
Here's the code I'm using, if it helps:
<?php
// Directory Location
$directory = './';
// Timezone (UK BST)
date_default_timezone_set(WET);
// Define Byte Sizes
function file_size($size)
{
$filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 1) . $filesizename[$i] : '0 Bytes';
}
// fetches all executable files in that directory and loop over each
foreach(glob($file.'*wav') as $file) {
// List Link to Files & Date/Time
echo '<a class="files" href="'.$file.'">
<span class="time">' . date("m/d/Y H:i", filemtime($file));
// List File Name & Size
echo '</span> '.$file.'
Size: '.file_size(filesize($file)).'</a>';
}
?>
If possible I would prefer the download links to be generated in PHP for each individual file. The files are listed like this: https://i.stack.imgur.com/N8Lxa.png