Esempio n. 1
0
 /**
  * Tutaj należy przeprowadzić walidację i jeśli walidacja się powiedzie to przenieść do katalogu tymczasowego
  * katalog tymczasowy powinien być w przestrzeni katalogowej widocznej z web
  * na koniec zwracamy dane dotyczące nowego pliki, najważniejsze w tych danych jest aby podać ścieżkę
  * od web do pliku, tak aby na stronie można było załadować
  * po drodze należy także ustawić path do przekazywania w polu hidden.
  *
  * @param UploadedFile $file
  * @param Form         $form
  * @param UploadResult $result
  *
  * @throws Exception
  */
 public function handle(UploadedFile $file, UploadResult $result)
 {
     throw new Exception('Method not implemented');
     // validate and if error
     $result->addError('File too big');
     // if ok move file and pass new path
     $config = $this->getConfig();
     $newfilename = Urlizer::urlizeCaseSensitiveTrim(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
     $ext = $file->guessExtension();
     if (!$ext) {
         $ext = 'bin';
     }
     $newfilename .= '.' . $ext;
     $directory = $this->generateSafeDirPrefix($newfilename);
     $file->move($config['web'] . $config['dirtmp'] . $directory, $newfilename);
     $result->setResponse(array('web' => $config['dirtmp'] . $directory . '/' . $newfilename));
     $result->setPath($directory . '/' . $newfilename);
 }
Esempio n. 2
0
 public function handle(UploadedFile $file, UploadResult $result)
 {
     // validate and if error
     //        $result->addError('File too big');
     $ext = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
     if (!in_array($ext, explode(' ', 'pdf doc docx png bmp jpeg jpg txt'))) {
         $result->addError("File extension '{$ext}' not allowed");
         return;
     }
     // if ok move file and pass new path
     $config = $this->getConfig();
     $newfilename = Urlizer::urlizeCaseSensitiveTrim(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
     $ext = $file->guessExtension();
     if (!$ext) {
         $ext = 'bin';
     }
     $newfilename .= '.' . $ext;
     $directory = $this->generateSafeDirPrefix($newfilename);
     $file->move($config['web'] . $config['dirtmp'] . $directory, $newfilename);
     $result->setResponse(array('webPath' => $config['dirtmp'] . $directory . '/' . $newfilename, 'path' => $directory . '/' . $newfilename));
     $result->setPath($directory . '/' . $newfilename);
 }
Esempio n. 3
0
 public static function header($name)
 {
     $name = Urlizer::urlizeTrim($name);
     header('X-' . $name . ': ' . static::get());
 }
Esempio n. 4
0
 public function generateSlug($table, $column, $title, $dbal = 'default')
 {
     $slug = Urlizer::urlizeTrim($title);
     $dbal = AbstractApp::getDbal($dbal);
     $stmt = $dbal->prepare("SELECT count(*) c FROM {$table} WHERE {$column} = :slug");
     $i = 0;
     do {
         if ($i) {
             $slug = UtilString::incrementString($slug, '-', 1);
         }
         ++$i;
         $stmt->bindValue('slug', $slug);
         $stmt->execute();
         $row = $stmt->fetch(PDO::FETCH_ASSOC);
     } while ($row['c']);
     return $slug;
 }