Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php] zmienna $_FILES -zabezpieczenia
Forum PHP.pl > Forum > Przedszkole
mefjiu
Czy takie zabezpieczenia wystarcz± dla $_FILES ?

  1. <?php
  2. if (in_array($_FILES['a_img_file']['type'], $accepted)==FALSE) {
  3. $blad++;
  4. $errors[] = "Niepoprawny format pliku, tylko jpg, jpeg, gif, png.<br />\n";
  5. }
  6. elseif ( $_FILES['a_img_file']['size'] > 1024000) {
  7. $blad++;
  8. $errors[] = "Plik nie mo¿e byæ wiêkszy ni¿ 1 mb.<br />\n";
  9. }else{}
  10. ?>
Cezar708
Cytat(mefjiu @ 26.02.2008, 10:21:30 ) *
Czy takie zabezpieczenia wystarcz± dla $_FILES ?


ogólnie tak... tylko powiedz przed czym chcesz siê zabezpieczyæ!
Cysiaczek
Mo¿esz jeszcze dodaæ pole input w formularzu.
  1. <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
mefjiu
Chcê siê zabezpieczyæ przed osobami szukaj±cymi luk w takich formularzach

co spowoduje dodanie tego
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
bo sprawdzanie wielko¶ci pliku mam po stronie php
specialplan
Ja bym jeszcze sprawdzil:

  1. <?php
  2. /**
  3. * Allowed file extensions
  4. * @array
  5. */
  6. public $allowed_extensions = array();
  7.  
  8. /**
  9. * Allowed mime-types of uploaded files
  10. * @array
  11. */
  12. public $allowed_mime_types = array();
  13.  
  14. /**
  15. * Get file extension
  16. * @return string extension
  17. */
  18. public function getExtension()
  19. {
  20. $file = pathinfo($this->getFileName());
  21. return $file['extension'];
  22. }
  23.  
  24. /**
  25. * Get MIME (uses FILEINFO extension, howerer, if it is not compiled, extracts the mime 
    type from a request constant)
  26. * @return string Mime-Type
  27. */
  28. public function getMimeType()
  29. {
  30. if (class_exists('finfo', false))
  31. {
  32.  $finfo = new finfo(FILEINFO_MIME);
  33.  if (file_exists($this->getTMPName()))
  34.  {
  35. return $finfo->file($this->getTMPName());
  36.  }
  37.  else
  38.  {
  39. return $finfo->file($this->upload_dir.$this->upload_file_name);
  40.  }
  41. }
  42. else
  43. {
  44.  return isset($this->data[$this->upload_form_field]['type']) ? $this->data[$this->upload_form_field]['type'] : null;
  45. }
  46. }
  47.  
  48. /**
  49. * Check if the mime-type of an uploaded file is allowed and throw an exception when it is not.
  50. * @return Exception - if not allowed, bool true if allowed
  51. */
  52. protected function checkMimeType()
  53. {
  54. if (!in_array($this->getMimeType(), $this->allowed_mime_types))
  55. {
  56. throw new Exception('Type of the uploaded file is not allowed. The accepted file types are: '.join(',<br />', $this->allowed_mime_types));
  57. }
  58. else
  59. {
  60. return true;
  61. }
  62. }
  63.  
  64. /**
  65. * Check the extension of an uploaded file
  66. * @return Exception - if not allowed, bool true if allowed
  67. */
  68. protected function checkExtension()
  69. {
  70. if (!in_array($this->getExtension(), $this->allowed_extensions))
  71. {
  72. throw new Exception('The extension of an uploaded file is not allowed. The accepted file extensions a
    re: '
    .join(', ', $this->allowed_extensions));
  73. }
  74. else
  75. {
  76. return true;
  77. }
  78. }
  79. ?>


To tylko wycinki klasy. Rozkmin Pan reszte sam:)

Pozdravki
mefjiu
ok spoko dziêki
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.