Check size before download
Add common.php with common functions
This commit is contained in:
parent
30cd0ba548
commit
f8d59cca32
8 changed files with 455 additions and 308 deletions
104
htdocs/dl.php
104
htdocs/dl.php
|
|
@ -1,80 +1,54 @@
|
|||
<?php
|
||||
define("MAIN_DIR", __dir__."/..");
|
||||
|
||||
function get_info($url)
|
||||
{
|
||||
$ec = file(MAIN_DIR."/database",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
$nbLign = count($ec);
|
||||
|
||||
for ($i = 0; $i < $nbLign; $i++)
|
||||
{
|
||||
if ($ec[$i] == $url)
|
||||
break;
|
||||
else
|
||||
{
|
||||
while ($i < $nbLign && trim($ec[$i]) != "--")
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($i+2 < $nbLign)
|
||||
{
|
||||
if ($ec[$i+3] == "-- ")
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+2]);
|
||||
else
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+3]);
|
||||
@$filenameogg = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.ogg', $filename);
|
||||
return @array($ec[$i], $ec[$i+1], $ec[$i+2], $ec[$i+3], trim($filename), trim($filenameogg));
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$user = "generic";
|
||||
foreach ($_GET as $k => $t)
|
||||
{
|
||||
if (empty($t))
|
||||
{
|
||||
$user = $k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!preg_match("#^[a-zA-Z0-9_]+$#", $user))
|
||||
die ("Le nom d'utilisateur contient des caractères interdits.");
|
||||
require(MAIN_DIR."/common.php");
|
||||
|
||||
if (isset($_GET["s"]))
|
||||
$stream = "inline";
|
||||
else
|
||||
$stream = "attachment";
|
||||
|
||||
if (isset($_GET["f"]))
|
||||
{
|
||||
if (is_file(MAIN_DIR."/users/".$user.".dlist.done"))
|
||||
$musiks = get_dlmusiks($user);
|
||||
|
||||
foreach ($musiks as $k => $lign)
|
||||
{
|
||||
$ec = file(MAIN_DIR."/users/".$user.".dlist.done",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
foreach ($ec as $k => $lign)
|
||||
if ($k == $_GET["f"])
|
||||
{
|
||||
if ($k == $_GET["f"])
|
||||
$musik = get_info($lign["url"]);
|
||||
if (isset($musik) && (is_file(MAIN_DIR."/content/".$musik["mp3"])
|
||||
|| is_file(MAIN_DIR."/content/".$musik["ogg"])))
|
||||
{
|
||||
$musik = get_info($lign);
|
||||
if (isset($musik) && (is_file(MAIN_DIR."/content/".$musik[4]) || is_file(MAIN_DIR."/content/".$musik[5])))
|
||||
if (is_file(MAIN_DIR."/content/".$musik["ogg"]))
|
||||
{
|
||||
if (is_file(MAIN_DIR."/content/".$musik[5]))
|
||||
$filename = MAIN_DIR."/content/".$musik[5];
|
||||
else
|
||||
$filename = MAIN_DIR."/content/".$musik[4];
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
if (is_file(MAIN_DIR."/content/".$musik[5]))
|
||||
header("Content-Disposition: attachment; filename=\"".$musik[1].".ogg\"");
|
||||
else
|
||||
header("Content-Disposition: attachment; filename=\"".$musik[1].".mp3\"");
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($filename));
|
||||
readfile($filename);
|
||||
exit;
|
||||
$filename = MAIN_DIR."/content/".$musik["ogg"];
|
||||
$ext = ".ogg";
|
||||
}
|
||||
else
|
||||
{
|
||||
$filename = MAIN_DIR."/content/".$musik["mp3"];
|
||||
$ext = ".mp3";
|
||||
}
|
||||
|
||||
//Mark file as dled
|
||||
mark_as_dled($user, $k);
|
||||
|
||||
if (is_file(MAIN_DIR."/content/".$musik["ogg"]))
|
||||
$fname = MAIN_DIR."/content/".$musik["ogg"];
|
||||
else
|
||||
$fname = MAIN_DIR."/content/".$musik["mp3"];
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: '.mime_content_type($filename));
|
||||
header("Content-Disposition: ".$stream."; filename=\"".addslashes($musik["title"]).$ext."\"");
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
//header('Expires: 0');
|
||||
//header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($filename));
|
||||
readfile($filename);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue