Share Pastebin
Guest
Private paste!

Untitled

By: a guest | Apr 15th, 2010 | Syntax: PHP | Size: 2.14 KB | Hits: 203 | Expires: Never
Copy text to clipboard
  1. <?php
  2. RASB::put_header('Bestand uploaden');
  3.  
  4. // Limit reached?
  5. if(!SessionUser::get_value('is_teacher'))
  6. {
  7.         $stats = Database::get()->row("SELECT COUNT(1) AS count,SUM(size) AS size FROM files WHERE user_id = '" . SessionUser::get_value('id') . "';");
  8.         if($stats['count'] >= 10)
  9.         {
  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.');
  11.                 RASB::put_footer();
  12.                 exit();
  13.         }
  14. }
  15.  
  16. // Process upload?
  17. if(RASB::form_submitted())
  18. {
  19.         $upload = &$_FILES['file'];
  20.         if($upload['error'])
  21.         {
  22.                 RASB::put_notification('Foutmelding: ' . $upload['error']);
  23.         }
  24.         elseif($upload['size'] > (10 * 1024 * 1024))
  25.         {
  26.                 RASB::import_lib('filefunctions');
  27.                 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!');
  28.         }
  29.         else
  30.         {
  31.                 // Filter input
  32.                 $upload['name'] = SecurityUtil::filter_string($upload['name']);
  33.                 $upload['type'] = SecurityUtil::filter_string($upload['type']);
  34.                
  35.                 // Generate ID
  36.                 $fileID = strtoupper(substr(md5(uniqid(rand(), true)),0,16));
  37.                
  38.                 // Move file
  39.                 move_uploaded_file($upload['tmp_name'], ROOTDIR . 'user_uploads/' . $fileID);
  40.                
  41.                 // Store location in database
  42.                 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');");
  43.                 RASB::put_notification('Je bestand "' . $upload['name'] . '" is geupload! ' . hyperlink('Downloaden/delen', mklink('files/get', array('id' => $fileID))));
  44.         }
  45. }
  46. ?>
  47.  
  48. <p>Nadat je bestand is geupload, kun je de link delen met andere gebruikers.</p>
  49. <p><strong>Let op:</strong> je bestand mag niet groter dan 10 MB zijn.</p>
  50.  
  51. <form id="uploader" action="" method="post" enctype="multipart/form-data">
  52.         Kies het bestand dat je wil uploaden: <input name="file" type="file" /><br />
  53.         <input id="btnUpload" name="uploadFile" type="submit" value="Uploaden" />
  54. </form>
  55.  
  56. <?php
  57. RASB::put_footer();
  58. ?>