Mam pole file_name w formularzu opdowiedzilne za upload pojedynczego pliku. Formularz jest walidowany poprawnie (mimo, że nie powinien) kiedy uploaduję plik: Audyt dla strony http.doc kiedy w folderze uploads jest plik: audyt-dla-strony-http.doc

  1. $kontrolka = new Zend_Form_Element_File('file_name', array(
  2. 'label' => 'Dodaj plik:',
  3. 'destination' => realpath(APPLICATION_PATH . '/../public/uploads'),
  4. 'required' => true,
  5. 'filters' => array(new My_Filters_Uploader()),
  6. 'validators' => array(
  7. array('Count', true, 1),
  8. array('Size', true, 102400),
  9. array('Db_NoRecordExists', false, array('table' => 'e_exercise','field' => 'file_name')),
  10. array('NotExists', false, realpath(APPLICATION_PATH . '/../public/uploads')),
  11. array('Extension', false, array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'odt', 'pdf'))
  12. ),
  13. ));
  14.  
  15.  
  16. //Filtr My_Filters_Uploader
  17. public function filter($value)
  18. {
  19. $file = pathinfo($value);
  20. $valueFiltered = My_Slugs::string2slug($file['filename']);
  21. return $valueFiltered . '.' . $file['extension'];
  22. }
  23.  
  24. //akcja
  25. if ($form->isValid($this->getRequest()->getPost())) {
  26.  
  27.  
  28. //usuwanie poprzedniego pliku
  29. $fld = realpath(APPLICATION_PATH . '/../public/uploads');
  30. $plik = $DbTable->getFile($eid);
  31. $np = realpath($fld . '/' . $plik);
  32. if (file_exists($np) && is_file($np))
  33. {
  34. chmod($np, 0777);
  35. unlink($np);
  36. }
  37. //usuwanie poprzedniego pliku
  38.  
  39. $data = $form->getValues();
  40. $data = array_merge($data, array('edit_date' => date('Y-m-d')));
  41. $obj->setFromArray($data);
  42. $obj->save();
  43.  
  44.  
  45.  
  46.  
  47. return $this->_helper->redirector(
  48. 'editexercise',
  49. $this->getRequest()->getcontrollerName(),
  50. $this->getRequest()->getModuleName(),
  51. array('eid' => $eid,
  52. 'id' => $id)
  53. );
  54.  
  55.  
  56. }
  57.  
  58. //string2slug
  59. public static function string2slug($string = '', $options = array('encoding' => 'windows-1250'))
  60. {
  61.  
  62. if (!isset($options['separator'])) {
  63. $options['separator'] = '-';
  64. }
  65.  
  66. if (!isset($options['default'])) {
  67. $options['default'] = 'undefined';
  68. }
  69.  
  70. if (!isset($options['encoding'])) {
  71. $options['encoding'] = 'utf-8';
  72. }
  73.  
  74. if (!isset($options['case'])) {
  75. $options['case'] = 'lower';
  76. }
  77.  
  78. switch ($options['encoding']) {
  79. case 'utf-8':
  80. $string = My_Pl::utf82ascii($string);
  81. break;
  82. case 'iso-8859-2':
  83. $string = My_Pl::iso2ascii($string);
  84. break;
  85.  
  86. case 'windows-1250':
  87. $string = My_Pl::win2ascii($string);
  88. break;
  89. }
  90.  
  91. $string = preg_replace('/[^A-Za-z0-9]/', $options['separator'], $string);
  92.  
  93. if (isset($options['case'])) {
  94. if ($options['case'] == 'lower') {
  95. $string = strtolower($string);
  96. } else if ($options['case'] == 'upper') {
  97. $string = strtoupper($string);
  98. }
  99. }
  100.  
  101. $string = preg_replace('/' . preg_quote($options['separator'], '/') . '{2,}/', $options['separator'], $string);
  102. $string = trim($string, $options['separator']);
  103.  
  104. if (isset($options['maxlength'])) {
  105. $string = self::abbr($string, $options);
  106. }
  107.  
  108. if ($string === '') {
  109. return $options['default'];
  110. } else {
  111. return $string;
  112. }
  113. }



EDIT: już nieważne