Advertisement
Stormix

Untitled

Aug 4th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. <?php
  2.  
  3. header('Content-type: text/plain');
  4.  
  5. /*
  6. ======================================================================
  7. MEGA drop. -File Hosting Platform
  8. Copyright (c) 2014 Anas Mazouni - Stormix. All rights reserved.
  9. ----------------------------------------------------------------------
  10. http://www.stormix.co/
  11. http://www.facebook.com/stormiix
  12. ======================================================================
  13. */
  14.  
  15. // Include Config File
  16. include_once('includes/config.inc.php');
  17. // Include Functions File
  18. include_once('includes/func.inc.php');
  19. // Include Connection File
  20. include_once('includes/connect.inc.php');
  21.  
  22. //Define a variable holding a temporary username
  23. $username = $_SESSION['user'] ;
  24. $allowed_files = $CONF['allowed_files'];
  25.  
  26. //Upload file
  27. if (!empty($_FILES)) {
  28. /* Define variables */
  29. $file = $_FILES['file'];
  30. //Convert the file size to byte
  31. $max_size = ($CONF['max_file_size']*1024)*1024;
  32. //Get File name
  33. $ds = DIRECTORY_SEPARATOR;
  34. $filename = $file['name'];
  35. $tempfile = $file['tmp_name'];
  36. $targetPath = dirname( __FILE__ ) . $ds. "drop" . $ds;
  37. $target = $targetPath.time()."_".$filename;
  38. //Check if $_FILES variable is now empty
  39. if (!empty($_FILES)) {
  40. //Check if file type is allowed
  41. if($allowed_files == "All" OR in_array($file['type'],$allowed_files) OR in_array("All",$allowed_files)){
  42. //Check if any error occurred
  43. if($file['error'] == "0"){
  44. //Check if file is smaller than file size
  45. if($file['size'] <= $max_size){
  46. //Check if file is uploaded
  47. if(move_uploaded_file($tempfile,$target)){
  48. /*------------------------------------------------------------------------------------------------------------ */
  49. //Mysql commands
  50. $filename = $mysqli->real_escape_string($file['name']) ;
  51. $count = substr_count($filename, '.');
  52. $ext = explode('.',$filename);
  53. $type = $mysqli->real_escape_string(strtoupper($ext[$count])." File");
  54. $uploader =$mysqli->real_escape_string($_SESSION['user']);
  55. $key = substr(md5(rand(0,99999999)),0,8);
  56. $timestamp = time();
  57. $date = date('Y-m-d H:i:s');
  58. $size = bytesToSize($file['size']);
  59. $target = $mysqli->real_escape_string($target);
  60. //Insert query here
  61. /* ------------------------------------------------------------------------------------------------------------ */
  62. }else{$msg = "An error occurred while uploading."; exit($msg);}
  63. }else{$msg = "File is too big !</b>"; exit($msg);}
  64. }else{$msg = "An error occurred while uploading. <br>Error Code :".$file['error'] .""; exit($msg);}
  65. }else{$msg = "Invalid File Type"; exit($msg);}
  66. }else{$msg = "No files were selected"; exit($msg);}
  67.  
  68.  
  69. }else{header("location: index");}
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement