<?php 
require_once('scripts/sb_functions.php');
global $logged_in;
$logged_in = logged_in( true, true );
	
read_config();
sb_language( 'upload_img' );
	
if ( $_FILES[ 'userfile' ][ 'error' ] == 0 ) {
    if (!file_exists('images')) {
	$oldumask = umask(0);
	$ok = my_mkdir('images', 0777 );
	umask($oldumask);
    }
    
    $uploaddir = 'images/';
    $uploadfile = $uploaddir . preg_replace("/ /","_",$_FILES[ 'userfile' ][ 'name' ]);
    
    if (getimagesize($_FILES['userfile']['tmp_name']) == FALSE){
	redirect_to_url( 'index.php' );		  
    }
    
    if ( move_uploaded_file($_FILES[ 'userfile' ][ 'tmp_name' ], $uploadfile ) ) {
	$ok = true;
    } else {
	$ok = false;
    }
} else {
    $ok = false;
}

if ( $ok === true ) {
    redirect_to_url( 'index.php' );
}

html_header('',false);

function page_content() {
    global $lang_string, $user_colors;
    if ( $ok !== true ) {
	echo( $lang_string[ 'error' ] . $ok . '<p />' );
    }
    echo( '<a href="index.php">' . $lang_string[ 'home' ] . '</a><br /><br />' );
}

theme_pagelayout();
html_footer();

?>
