ADD: started implementing downloader thru POST but it's janky and the resulting files are empty ._.

This commit is contained in:
TheShinyMelon 2025-03-13 00:02:44 +01:00
parent f284b620cb
commit 5f1b57cd87
3 changed files with 89 additions and 55 deletions

View File

@ -1,5 +1,6 @@
<?php <?php
$pdo; $pdo;
try { try {
$pdo = new PDO($dsn, $user, $passwd); $pdo = new PDO($dsn, $user, $passwd);
// if ($pdo) echo "Connected to the $dbname database successfully!"; // if ($pdo) echo "Connected to the $dbname database successfully!";
@ -8,6 +9,7 @@
echo $e->getMessage(); echo $e->getMessage();
} }
function get_images($pdo, $search='%', $sort='img_date', $sdir='DESC') { function get_images($pdo, $search='%', $sort='img_date', $sdir='DESC') {
if ($sort != 'img_date' && $sdir != 'ASC') { if ($sort != 'img_date' && $sdir != 'ASC') {
if ($sort != 'img_title' && $sdir != 'DESC') { if ($sort != 'img_title' && $sdir != 'DESC') {
@ -50,7 +52,7 @@ function get_audio($pdo, $search='%', $sort='aud_date', $sdir='DESC') {
foreach ($data as $block) { foreach ($data as $block) {
$aud_list .= '<li>'; $aud_list .= '<li>';
$aud_list .= '<div class="music_player">'; $aud_list .= '<div class="music_player">';
$aud_list .= '<img src="'.get_album_cover($block["aud_title"]).'">'; $aud_list .= '<img src="tba">';
$aud_list .= '<audio controls>'; $aud_list .= '<audio controls>';
$aud_list .= '<source src=\''.$block['aud_path'].'\' type="audio/mpeg">'; $aud_list .= '<source src=\''.$block['aud_path'].'\' type="audio/mpeg">';
$aud_list .= 'There would be an awesome music player here if you weren\'t such a weirdo...'; $aud_list .= 'There would be an awesome music player here if you weren\'t such a weirdo...';
@ -58,14 +60,9 @@ function get_audio($pdo, $search='%', $sort='aud_date', $sdir='DESC') {
$aud_list .= '</div>'; $aud_list .= '</div>';
$aud_list .= '<h4>'.$block['aud_title']."<br></h4>"; $aud_list .= '<h4>'.$block['aud_title']."<br></h4>";
$aud_list .= '<p class="list_text">'.$block['aud_desc']."</p>"; $aud_list .= '<p class="list_text">'.$block['aud_desc']."</p>";
$aud_list .= '<p><a href="'.$block['aud_path'].'">download</a></p>'; // TODO: mask dl link with helper class $aud_list .= '<p><form method="POST" action="'.$_SERVER['PHP_SELF'].'"><input name="dl_path" type="hidden" value="'.$block['aud_path'].'"><input value="download" type="submit"></form></p>';
$aud_list .= '</li>'; $aud_list .= '</li>';
} }
$aud_list .= '</ul>'; $aud_list .= '</ul>';
echo $aud_list; echo $aud_list;
} }
function get_album_cover($title) {
// TODO: put actual code here, maybe steal from this lib https://github.com/wapmorgan/Mp3Info/blob/master/src/Mp3Info.php
return "nopathyet";
}

View File

@ -0,0 +1,32 @@
<?php
function downloader($path, $mm_type="application/octet-stream") {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " . filesize($path) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");
ob_clean();
flush();
$chunk_size = 8192;
$handle = fopen($path, 'rb');
if ($handle) {
while (!feof($handle)) {
echo fread($handle, $chunk_size);
flush();
}
fclose($handle);
}
die(); // TODO: Fix file being empty ._.
}
//https://www.kavoir.com/2009/05/php-hide-the-real-file-url-and-provide-download-via-a-php-script.html

View File

@ -61,6 +61,11 @@
include('404.php'); include('404.php');
break; break;
} }
if($_SERVER["REQUEST_METHOD"] == "POST") {
require_once('../app/downloader.php');
downloader($_POST['dl_path']);
}
?> ?>
</div> </div>