rendered paste body<?php
usleep(500);
require_once("db_inc.php");
require_once("config.php");
require_once("getinfo.php");
$admin = isset($_SESSION['admin']) && $_SESSION['admin'] == true ? $_SESSION['admin'] : false; // Admin eller ej?
function getRewriteString($string) {
$string = htmlentities(strtolower($string));
$string = preg_replace("/&(.)(acute|cedil|circ|ring|tilde|uml);/", "$1", $string);
$string = preg_replace("/([^a-z0-9. _()]+)/", "-", html_entity_decode($string));
$string = trim($string, "_");
return $string;
}
$res = mysql_query("SELECT COUNT(*) FROM gms_bans WHERE IP=".ip2long($_SERVER['REMOTE_ADDR']));
list($banned) = mysql_fetch_row($res);
mysql_free_result($res);
if($banned) {
usleep(20000);
header("Location: index.php#".$id);
}
if(!$_POST['upload']) die();
$res = mysql_query("SELECT UNIX_TIMESTAMP(MIN(NOW() - upload_time)) FROM uploads WHERE ip=".ip2long($_SERVER['REMOTE_ADDR']));
list($last_uploaded) = mysql_fetch_row($res);
$last_uploaded = ($last_uploaded == NULL) ? time() : $last_uploaded;
mysql_free_result($res);
if($last_uploaded >= SECONDS_BETWEEN_UPLOADS || !$rumrows || $admin ) {
$uploadfile = SONG_DIRECTORY . ($filename = getRewriteString(basename($_FILES['songfile']['name'])));
if(is_uploaded_file($tmpfile = $_FILES['songfile']['tmp_name'])) {
$suffix = strtolower(strrchr($filename, '.'));
if(!in_array($suffix, $allowed_suffixes)) {
echo "$suffix-filer ej tillåtna. Tillåtna: <br>\r\n";
foreach($allowed_suffixes as $s) {
echo ".$s ";
}
} else {
if(filesize($tmpfile) > MAX_SONG_FILESIZE<<20) {
die("Högsta filstorlek: ".MAX_SONG_FILESIZE."Mb");
}
$md5 = md5_file($tmpfile);
$res = mysql_query("SELECT COUNT(*) FROM songs WHERE md5='$md5'");
list($cnt) = mysql_fetch_row($res);
mysql_free_result($res);
if($cnt) {
$res = mysql_query("SELECT filename FROM songs WHERE md5='$md5'");
list($already_uploaded) = mysql_fetch_row($res);
mysql_free_result($res);
echo "Låten finns redan uppladdad som: <b>".basename($already_uploaded)."</b><br>\r\n";
} else {
if (rename($_FILES['songfile']['tmp_name'], $uploadfile)) {
extract(getinfo($uploadfile));
mysql_query("INSERT INTO songs (filename, length, title, artist, album, genre, `year`, md5, num_votes, last_played, when_uploaded, uploader_ip) VALUES ('$uploadfile', ".(0+$length).", '$title', '$artist', '$album','$genre' ,".intval($year).", '$md5', 1, 0, NOW(), ".ip2long($_SERVER['REMOTE_ADDR']).")");
$id = mysql_insert_id();
mysql_query("INSERT INTO uploads (ip, song, upload_time) VALUES (".ip2long($_SERVER['REMOTE_ADDR']).", $id, NOW())");
header("Location: index.php#".$id);
}
}
}
} else { echo "Något gick fel med filuppladdningen."; die();}
} else {
usleep(20000);
}
header("Location: index.php");
?>