prefs['upload'] || conf('demo_mode')) {
access_denied();
}
/* Action Settings */
$action = scrub_in($_REQUEST['action']);
/*
FILE UPLOAD SECTION
This section handles file uploads. File types should
be declared in the $types hash. This will provide
an easy lookup mechanism.
*/
$types = array(
'mp3'=>'music',
'MP3'=>'music',
'ogg'=>'music',
'OGG'=>'music',
'WMA'=>'music',
'FLAC'=>'music',
'flac'=>'music',
'm4a' =>'music',
'aac' =>'music',
'.gz'=>'compressed',
'tar'=>'compressed',
'zip'=>'compressed',
'ZIP'=>'compressed',
);
/* Upload Section Which Processes All Files Sent As Post */
$audio_info = new Audioinfo();
switch ($action) {
case 'upload_now':
// Verify the needed settings are in place
if (!@chdir($user->prefs['upload_dir']) || strlen($user->prefs['upload_dir']) < 1) {
break;
}
//FIXME: Set which catalog it goes into somewhere....
$sql = "SELECT * FROM catalog LIMIT 1";
$db_results = mysql_query($sql, dbh());
$results = mysql_fetch_object($db_results);
$catalog = new Catalog($results->id);
// Create arrays
$filelist = array();
foreach($_FILES as $tagname=>$file){
/* Skip blank file names */
if( strlen($file['name'] ) ){
// Determine tempfile name
$tempfile = $file['tmp_name'];
// Determine real file name
$realname = $user->prefs['upload_dir'] . "/" . $file['name'];
/* Determine Extension */
$ext = substr( $file['name'], -3 );
/* Prevent Unauthorized file types */
if( $types[$ext] == 'compressed' ){
// This section is currently disabled
}
elseif( $types[$ext] == 'music' ){
$error = @move_uploaded_file($tempfile, $realname );
if( $error )
{
$filelist = array( $realname => $file['name'] );
}
else{
switch ($file['error']) {
case '1':
$error_text = _("The uploaded file exceeds the upload_max_filesize directive in php.ini");
break;
case '2':
$error_text = _("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.");
break;
case '3':
$error_text = _("The uploaded file was only partially uploaded.");
break;
case '4':
$error_text = _("No file was uploaded.");
break;
default:
$error_text = _("An Unknown Error has occured.");
break;
} // end switch
if (conf('debug')) {
log_event($_SESSION['userdata']['username'],'upload',$error_text);
}
$message[$file['name']] .= "Error: $error_text";
$errorenum[$file['name']]=true;
}
} // end if known
// If unknown filetype
else{
$message[$file['name']] .= "Error: Unsupported File Type- $ext
";
$errorenum[$file['name']]=true;
}
// foreach through files uploaded
foreach( $filelist as $fullpath => $music ) {
// If we are quarantining the file
if ($user->prefs['quarantine']) {
// Log the upload but don't do anything
$message[$music] .= _("Successfully-Quarantined");
/* Log the upload */
$sql = "INSERT INTO upload (`user`,`file`,`addition_time`)" .
" VALUES ('$user->username','" . sql_escape($fullpath) . "','" . time() . "')";
$db_results = mysql_query($sql, dbh());
} // if quarantine
// Go ahead and insert the file
else {
$catalog->insert_local_song($fullpath,filesize($fullpath));
$message[$music] .= _("Successfully-Cataloged");
} // end foreach
flush();
}
}
} // end foreach
flush();
/* Display Upload results */
if( $message ){
print( "
Filename | Result | \n" ); foreach ( $message as $key => $value ){ if( $errorenum[$key] ){ $color="color='red'"; } else{ $color="color='green'"; } print( "
---|---|
$key | $value | \n"); print( "
\n" .
" " . _("Add") . " \n" . " " . _("Delete") . " \n" . " | \n";
}
else{
echo " " . _("Quarantined") . " | \n"; } echo "" . $results[$key][title] . " | \n"; echo "" . $results[$key]['artist'] . "  | \n"; echo "" . $results[$key]['album'] . "  | \n"; echo "" . $results[$key]['genre'] . " | \n"; echo "" . $time . " | \n"; echo "" . intval($results['avg_bit_rate']/1000) . "-" . $results['bitrate_mode'] . " | \n"; echo "" . sprintf("%.2f",($filesize/1048576)) . " | \n"; echo "$file | \n"; echo "$uname | \n"; echo "$add_time | \n"; echo "