Guest User

h3h3

a guest
Oct 9th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.13 KB | None | 0 0
  1. <?php
  2.  
  3. ####################################################################
  4. # File Upload Form 1.1
  5. ####################################################################
  6. # For updates visit http://www.zubrag.com/scripts/
  7. ####################################################################
  8.  
  9. ####################################################################
  10. # SETTINGS START
  11. ####################################################################
  12.  
  13. // Folder to upload files to. Must end with slash /
  14. define('DESTINATION_FOLDER','/hemija/');
  15.  
  16. // Maximum allowed file size, Kb
  17. // Set to zero to allow any size
  18. define('MAX_FILE_SIZE', 0);
  19.  
  20. // Upload success URL. User will be redirected to this page after upload.
  21. define('SUCCESS_URL','http://www.teameglory.info/hemija/');
  22.  
  23. // Allowed file extensions. Will only allow these extensions if not empty.
  24. // Example: $exts = array('avi','mov','doc');
  25. $exts = array();
  26.  
  27. // rename file after upload? false - leave original, true - rename to some unique filename
  28. define('RENAME_FILE', false);
  29.  
  30. // put a string to append to the uploaded file name (after extension);
  31. // this will reduce the risk of being hacked by uploading potentially unsafe files;
  32. // sample strings: aaa, my, etc.
  33. define('APPEND_STRING', '');
  34.  
  35. // Need uploads log? Logs would be saved in the MySql database.
  36. define('DO_LOG', false);
  37.  
  38. // MySql data (in case you want to save uploads log)
  39. define('DB_HOST','localhost'); // host, usually localhost
  40. define('DB_DATABASE','mydb'); // database name
  41. define('DB_USERNAME','myusername'); // username
  42. define('DB_PASSWORD','password-here'); // password
  43.  
  44. /* NOTE: when using log, you have to create mysql table first for this script.
  45. Copy paste following into your mysql admin tool (like PhpMyAdmin) to create table
  46. If you are on cPanel, then prefix _uploads_log on line 205 with your username, so it would be like myusername_uploads_log
  47.  
  48. CREATE TABLE _uploads_log (
  49. log_id int(11) unsigned NOT NULL auto_increment,
  50. log_filename varchar(128) default '',
  51. log_size int(10) default 0,
  52. log_ip varchar(24) default '',
  53. log_date timestamp,
  54. PRIMARY KEY (log_id),
  55. KEY (log_filename)
  56. );
  57.  
  58. */
  59.  
  60. ####################################################################
  61. ### END OF SETTINGS. DO NOT CHANGE BELOW
  62. ####################################################################
  63.  
  64. // Allow script to work long enough to upload big files (in seconds, 2 days by default)
  65. @set_time_limit(172800);
  66.  
  67. // following may need to be uncommented in case of problems
  68. ini_set("session.gc_maxlifetime","10800");
  69.  
  70. function showUploadForm($message='') {
  71. $max_file_size_tag = '';
  72. if (MAX_FILE_SIZE > 0) {
  73. // convert to bytes
  74. $max_file_size_tag = "<input name='MAX_FILE_SIZE' value='".(MAX_FILE_SIZE*1024)."' type='hidden' >\n";
  75. }
  76.  
  77. // Load form template
  78. include ('file-upload.html');
  79. }
  80.  
  81. // errors list
  82. $errors = array();
  83.  
  84. $message = '';
  85.  
  86. // we should not exceed php.ini max file size
  87. $ini_maxsize = ini_get('upload_max_filesize');
  88. if (!is_numeric($ini_maxsize)) {
  89. if (strpos($ini_maxsize, 'M') !== false)
  90. $ini_maxsize = intval($ini_maxsize)*1024*1024;
  91. elseif (strpos($ini_maxsize, 'K') !== false)
  92. $ini_maxsize = intval($ini_maxsize)*1024;
  93. elseif (strpos($ini_maxsize, 'G') !== false)
  94. $ini_maxsize = intval($ini_maxsize)*1024*1024*1024;
  95. }
  96. if ($ini_maxsize < MAX_FILE_SIZE*1024) {
  97. $errors[] = "Pozor! Maksimalna veličina uploadanog fajla u php.ini (upload_max_filesize) je manja nego od skripte MAX_FILE_SIZE";
  98. }
  99.  
  100. // show upload form
  101. if (!isset($_POST['submit'])) {
  102. showUploadForm(join('',$errors));
  103. }
  104.  
  105. // process file upload
  106. else {
  107.  
  108. while(true) {
  109.  
  110. // make sure destination folder exists
  111. if (!@file_exists(DESTINATION_FOLDER)) {
  112. $errors[] = "Destinacijski folder ne postoji ili nemate prava da vidite isti A.K..";
  113. break;
  114. }
  115.  
  116. // check for upload errors
  117. $error_code = $_FILES['filename']['error'];
  118. if ($error_code != UPLOAD_ERR_OK) {
  119. switch($error_code) {
  120. case UPLOAD_ERR_INI_SIZE:
  121. // uploaded file exceeds the upload_max_filesize directive in php.ini
  122. $errors[] = "File je prevelik, kontaktirajte facebook.com/amar.kalaba (1).";
  123. break;
  124. case UPLOAD_ERR_FORM_SIZE:
  125. // uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form
  126. $errors[] = "File je prevelik, kontaktirajte facebook.com/amar.kalaba (2).";
  127. break;
  128. case UPLOAD_ERR_PARTIAL:
  129. // uploaded file was only partially uploaded.
  130. $errors[] = "Nemoguce je uploadati taj fajl, molimo kontaktirajte facebook.com/amar.kalaba (1).";
  131. break;
  132. case UPLOAD_ERR_NO_FILE:
  133. // No file was uploaded
  134. $errors[] = "Nemoguce je uploadati taj fajl, molimo kontaktirajte facebook.com/amar.kalaba (2).";
  135. break;
  136. case UPLOAD_ERR_NO_TMP_DIR:
  137. // Missing a temporary folder
  138. $errors[] = "Nemoguce je uploadati taj fajl, molimo kontaktirajte facebook.com/amar.kalaba (3).";
  139. break;
  140. case UPLOAD_ERR_CANT_WRITE:
  141. // Failed to write file to disk
  142. $errors[] = "Nemoguce je uploadati taj fajl, molimo kontaktirajte facebook.com/amar.kalaba (4).";
  143. break;
  144. case 8:
  145. // File upload stopped by extension
  146. $errors[] = "Nemoguce je uploadati taj fajl, molimo kontaktirajte facebook.com/amar.kalaba (5).";
  147. break;
  148. } // switch
  149.  
  150. // leave the while loop
  151. break;
  152. }
  153.  
  154. // get file name (not including path)
  155. $filename = @basename($_FILES['filename']['name']);
  156.  
  157. // filename of temp uploaded file
  158. $tmp_filename = $_FILES['filename']['tmp_name'];
  159.  
  160. $file_ext = @strtolower(@strrchr($filename,"."));
  161. if (@strpos($file_ext,'.') === false) { // no dot? strange
  162. $errors[] = "Nepoznata ekstenzija ili nepovjerljivo ime.";
  163. break;
  164. }
  165. $file_ext = @substr($file_ext, 1); // remove dot
  166.  
  167. // check file type if needed
  168. if (count($exts)) { /// some day maybe check also $_FILES['user_file']['type']
  169. if (!@in_array($file_ext, $exts)) {
  170. $errors[] = "Fajlove ovog tipa je nemoguće uploadati.";
  171. break;
  172. }
  173. }
  174.  
  175. // destination filename, rename if set to
  176. $dest_filename = $filename;
  177. if (RENAME_FILE) {
  178. $dest_filename = md5(uniqid(rand(), true)) . '.' . $file_ext;
  179. }
  180. // append predefined string for safety
  181. $dest_filename = $dest_filename . APPEND_STRING;
  182.  
  183. // get size
  184. $filesize = intval($_FILES["filename"]["size"]); // filesize($tmp_filename);
  185.  
  186. // make sure file size is ok
  187. if (MAX_FILE_SIZE > 0 && MAX_FILE_SIZE*1024 < $filesize) {
  188. $errors[] = "Fajl je prevelik za upload (3).";
  189. break;
  190. }
  191.  
  192. if (!@move_uploaded_file($tmp_filename , DESTINATION_FOLDER . $dest_filename)) {
  193. $errors[] = "Nemoguce je uploadati taj fajl, molimo kontaktirajte facebook.com/amar.kalaba (6).";
  194. break;
  195. }
  196.  
  197. if (DO_LOG) {
  198. // Establish DB connection
  199. $link = @mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD);
  200. if (!$link) {
  201. $errors[] = "Nemoguce je kontaktirati MYSQL bazu, kontaktirajte administratora.";
  202. break;
  203. }
  204. $res = @mysql_select_db(DB_DATABASE, $link);
  205. if (!$res) {
  206. $errors[] = "Nemoguce je odrediti bazu, molimo kontaktirajte administratora.";
  207. break;
  208. }
  209. $m_ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
  210. $m_size = $filesize;
  211. $m_fname = mysql_real_escape_string($dest_filename);
  212. $sql = "insert into _uploads_log (log_filename,log_size,log_ip) values ('$m_fname','$m_size','$m_ip')";
  213. $res = @mysql_query($sql);
  214. if (!$res) {
  215. $errors[] = "Nemoguce je pokrenuti query, molimo kontaktirajte administratora..";
  216. break;
  217. }
  218. @mysql_free_result($res);
  219. @mysql_close($link);
  220. } // if (DO_LOG)
  221.  
  222.  
  223. // redirect to upload success url
  224. header('Location: ' . SUCCESS_URL);
  225. die();
  226.  
  227. break;
  228.  
  229. } // while(true)
  230.  
  231. // Errors. Show upload form.
  232. $message = join('',$errors);
  233. showUploadForm($message);
  234.  
  235. }
  236.  
  237. ?>
Advertisement
Add Comment
Please, Sign In to add comment