Вход Регистрация
* Balltazor

загрузка файлов на сервер

  1. <?php
  2. // upload.php //
  3. if (isset($_FILES['file'])) {
  4. $file = $_FILES['file'];
  5.  
  6. // параметры файла
  7. $file_name = $file['name'];
  8. $file_tmp = $file['tmp_name'];
  9. $file_error = $file['error'];
  10. $file_size = $file['size'];
  11. $file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
  12.  
  13. $allowed = array('txt', 'zip');
  14.  
  15. if (in_array($file_ext, $allowed)) {
  16. if ($file_error === 0) {
  17. if ($file_size <= 2097152) {
  18. $file_new_name = uniqid('', true) . '.' . $file_ext;
  19. $file_descination = 'uploads/' . $file_new_name;
  20.  
  21. if (move_uploaded_file($file_tmp, $file_descination)) {
  22. echo $file_descination;
  23. }
  24. }
  25. }
  26. }
  27. }
  28. ?>
  29.  
  30. // index.php //
  31.  
  32. <!DOCTYPE HTML>
  33. <html>
  34. <head>
  35. <meta http-equiv="content-type" content="text/html" />
  36. <meta name="author" content="admin" />
  37.  
  38. <title>Загрузка файла</title>
  39. </head>
  40.  
  41. <body>
  42.  
  43. <form action="upload.php" method="POST" enctype="multipart/form-data">
  44. <input type="file" name="file"/>
  45. <input type="submit" value="Загрузить"/>
  46. </form>
  47.  
  48. </body>
  49. </html>
» Описание: загрузка файлов на сервер
» Время добавления: 22 Июня 2014 в 14:54
» Посмотров: 1267
» textarea
» Рейтинг: [+0 | -0]
Комментарии [0]
Онлайн: 2
Реклама