Cześć
W którym miejscu i co powinienem wpisać abym mógł wybrać format pliku wysyłanego na server np: pdf, gif,rar.
Proszę o pomoc
PLIK INDEX.PHP
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  3. <head>
  4. <title>ES Simple Uploader</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  6. <meta name="generator" content="handmade" />
  7. <style type="text/css">
  8. <!--
  9. body {
  10. font-family: Arial, Helvetica, sans-serif;
  11. font-size: 14px;
  12. background-color: #DDDDDD;
  13. }
  14. .cnt {
  15. text-align: center;
  16. }
  17. .cnt_welcome {
  18. font-size: 16px;
  19. font-weight: bold;
  20. text-align: center;
  21. }
  22. .cnt_powered {
  23. font-size: 14px;
  24. font-weight: bold;
  25. text-align: center;
  26. }
  27. .cnt_small {
  28. font-size: 12px;
  29. text-align: center;
  30. padding-top: 50px;
  31. }
  32. .head_line {
  33. background-color: #BBBBBB;
  34. }
  35. .main_table {
  36. border: solid 1px #9D9992;
  37. font-size: 13px;
  38. }
  39. h4 {
  40. font-size: 12px;
  41. color: #DD0000;
  42. text-align: center;
  43. }
  44. .button {
  45. border: 1px solid #55555;
  46. font-weight: bold;
  47. }
  48. -->
  49. </style>
  50. </head>
  51.  
  52. <body>
  53. <?
  54. include("config.php");
  55.  
  56. function path_options()
  57. {
  58. global $upload_dirs;
  59. $option = "";
  60. foreach ($upload_dirs as $path => $pinfo)
  61. {
  62. $option .= '<option value="'.$path.'">'.$pinfo["name"].'</option>';
  63. }
  64. return $option;
  65. }
  66.  
  67. function check_vals()
  68. {
  69. global $upload_dirs, $err;
  70. if (!ini_get("file_uploads")) { $err .= "HTTP file uploading is blocked in php configuration file (php.ini). Please, contact to server administrator."; return 0; }
  71. $pos = strpos(ini_get("disable_functions"), "move_uploaded_file");
  72. if ($pos !== false) { $err .= "PHP function move_uploaded_file is blocked in php configuration file (php.ini). Please, contact to server administrator."; return 0; }
  73. if (!isset($_POST["path"]) || (strlen($_POST["path"]) == 0)) { $err .= "Please fill out path"; return 0; }
  74. if (!isset($upload_dirs[$_POST["path"]])) { $err .= "Incorrect path"; return 0; }
  75. if (!isset($_POST["pwd"]) || (strlen($_POST["pwd"]) == 0)) { $err .= "Please fill out password"; return 0; }
  76. elseif ($_POST["pwd"] != $upload_dirs[$_POST["path"]]["password"]) { $err .= "The upload password is incorrect"; return 0; }
  77. if (!isset($_FILES["userfile"])) { $err .= "Empty file"; return 0; }
  78. elseif (!is_uploaded_file($_FILES['userfile']['tmp_name'])) { $err .= "Empty file"; return 0; }
  79. return 1;
  80. }
  81.  
  82. $err = ""; $status = 0;
  83. if (isset($_POST["upload"])) {
  84. if (check_vals()) {
  85. if (filesize($_FILES["userfile"]["tmp_name"]) > $max_file_size) $err .= "Maximum file size limit: $max_file_size bytes";
  86. else {
  87. if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $upload_dirs[$_POST["path"]]["dir"].$_FILES["userfile"]["name"])) {
  88. $status = 1;
  89. }
  90. else $err .= "There are some errors!";
  91. }
  92. }
  93. }
  94.  
  95. if (!$status) {
  96. if (strlen($err) > 0) echo "<h4>$err</h4>";
  97. }
  98. else {
  99. echo "<h4>&quot;".$_FILES["userfile"]["name"]."&quot; został poprawnie wysłany.</h4>";
  100. }
  101. ?>
  102.  
  103. <form enctype="multipart/form-data" action="index.php" method="POST">
  104. <input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
  105. <table class="main_table" align="center">
  106. <tr>
  107. <td colspan="2" class="head_line">&nbsp;</td>
  108. </tr>
  109. <tr>
  110. <td>Folder:</td>
  111. <td><select name="path"><?=path_options()?></select></td>
  112. </tr>
  113. <tr>
  114. <td>Password:</td>
  115. <td><input type="password" name="pwd" style="width: 217px;" /></td>
  116. </tr>
  117. <tr>
  118. <td>Choose file:</td>
  119. <td><input type="file" name="userfile" style="width: 222px;" /></td>
  120. </tr>
  121. <tr>
  122. <td colspan="2" align="right"><input type="submit" name="upload" value="Upload" class="button" /></td>
  123. </tr>
  124. </table>
  125. </form>
  126. </p>
  127. </body>
  128. </html>


PLIK CONFIG.PHP
  1. <?
  2. /*
  3. Upload dirs(folders) list
  4. - - - - - - - - - - - - - - - - - -
  5.   "images" => array(
  6.   "dir" =>"uploads/images",
  7.   "password"=>"images",
  8.   ),
  9. - - - - - - - - - - - - - - - - - -
  10. "images" - just section name (any name you like), it is a key
  11. "name" - the dir(folder) name in select box
  12. "dir" - path to uploaded files
  13. "password" - "dir" password
  14. */
  15. $upload_dirs = array(
  16. "images" => array(
  17. "dir" =>"uploads/zdjecia/",
  18. "name" =>"zdjecia",
  19. "password"=>"ges",
  20. ),
  21. "docs" => array(
  22. "dir" =>"uploads/prezentacje/",
  23. "name" =>"prezentacje",
  24. "password"=>"cje",
  25. ),
  26. "common" => array(
  27. "dir" =>"uploads/html_zyciorys/",
  28. "name" =>"html zyciorys",
  29. "password"=>"rys",
  30. ),
  31. );
  32.  
  33. $max_file_size = 500000*1024; //max file upload size (bytes)
  34. ?>