if( !defined('in_system') )
{
echo "access denied";
exit;
}$do_upload = new do_upload;
class do_upload {
function do_upload()
{
global $std, $lang, $config;
$today = date("d").date("m").date("y");
$upload_dir = $config.$today."/";
if( !is_dir($upload_dir) )
{
mkdir($upload_dir,0777);
}
$size_bytes = $conifg;
$allowed_file_type = $config;
if( !is_dir($upload_dir) ) // if the upload dir does not exsit
{
$std->header();
$std->error_screen($lang);
$std->footer();
}
if( !is_writeable($upload_dir) ) // if the upload dir is not writable
{
$std->header();
$std->error_screen($lang);
$std->footer();
}
if( is_uploaded_file($_FILES]) ) // if user sent a file to upload
{
$filesize = $_FILES];
if( $filesize > $std->mb2bytes($config) ) // if user's file size is bigger then max file size which allowed
{
$std->header();
$std->error_screen($lang);
$std->footer();
}
$file_type = explode("/",$_FILES]);
$myFileType = $file_type;
if( $config == 1 && ! in_array( $myFileType , $config ) ) // if user's file type is not allowed
{
$std->header();
$std->error_screen($lang);
$std->footer();
}
// ########
// Create new file name
// ########
$filename = $_FILES];
$now = time();
$number = rand(1000,9999);
$new_name = substr($now,6,10).substr($number,1,3);
$type = $myFileType;
if ( move_uploaded_file($_FILES],$upload_dir.$new_name.".".$type) ) // if upload succeed
{
$std->header();
$link = "<a href=\"$upload_dir$new_name.$type\">$new_name</a>";
$std->print_html( file_uploaded( $link ) );
$std->footer();
exit;
} else {
// if was a problem during uploading
$std->header();
$std->error_screen($lang);
$std->footer();
}
} else {
// If user did not send a file to upload
$std->header();
$std->error_screen($lang);
$std->footer();
}
}
}
?>