Untitled
By: a guest | Apr 15th, 2010 | Syntax:
PHP | Size: 2.14 KB | Hits: 203 | Expires: Never
<?php
RASB::put_header('Bestand uploaden');
// Limit reached?
if(!SessionUser::get_value('is_teacher'))
{
$stats = Database::get()->row("SELECT COUNT(1) AS count,SUM(size) AS size FROM files WHERE user_id = '" . SessionUser::get_value('id') . "';");
if($stats['count'] >= 10)
{
RASB::put_notification('Je hebt je limiet (10 bestanden) bereikt en je kunt niet meer uploaden. ' . hyperlink('Verwijder bestanden', mklink('files')) . ' om ruimte te maken.');
RASB::put_footer();
exit();
}
}
// Process upload?
if(RASB::form_submitted())
{
$upload = &$_FILES['file'];
if($upload['error'])
{
RASB::put_notification('Foutmelding: ' . $upload['error']);
}
elseif($upload['size'] > (10 * 1024 * 1024))
{
RASB::import_lib('filefunctions');
RASB::put_notification('Sorry, maar de grootte van dit bestand is ' . file_size_name($upload['size']) . '. Je bestand mag niet groter zijn dan 10 MB!');
}
else
{
// Filter input
$upload['name'] = SecurityUtil::filter_string($upload['name']);
$upload['type'] = SecurityUtil::filter_string($upload['type']);
// Generate ID
$fileID = strtoupper(substr(md5(uniqid(rand(), true)),0,16));
// Move file
move_uploaded_file($upload['tmp_name'], ROOTDIR . 'user_uploads/' . $fileID);
// Store location in database
Database::get()->execute("INSERT INTO files(id,name,mime,size,user_id,submitted_at,downloads) VALUES ('" . $fileID . "','" . $upload['name'] . "','" . $upload['type'] . "','" . $upload['size'] . "','" . SessionUser::get_value('id') . "',NOW(),'0');");
RASB::put_notification('Je bestand "' . $upload['name'] . '" is geupload! ' . hyperlink('Downloaden/delen', mklink('files/get', array('id' => $fileID))));
}
}
?>
<p>Nadat je bestand is geupload, kun je de link delen met andere gebruikers.</p>
<p><strong>Let op:</strong> je bestand mag niet groter dan 10 MB zijn.</p>
<form id="uploader" action="" method="post" enctype="multipart/form-data">
Kies het bestand dat je wil uploaden: <input name="file" type="file" /><br />
<input id="btnUpload" name="uploadFile" type="submit" value="Uploaden" />
</form>
<?php
RASB::put_footer();
?>