| 597 | |
| 598 | == Jak wywołać mechanizm wgrywania pliku na serwer == |
| 599 | {{{ |
| 600 | // widget do wgrywania pliku w klasie np MyClassCustomWidget |
| 601 | require_once(LIB_PATH.'widgets/SimpleUploader.inc'); |
| 602 | $fileUpload = new SimpleUploader($this->name.'fileUpload'); |
| 603 | $fileUpload->left = '102px'; |
| 604 | $fileUpload->bottom = '10px'; |
| 605 | $fileUpload->width = '140px'; |
| 606 | $fileUpload->height = '20px'; |
| 607 | $fileUpload->addEventListener(SimpleUploader::ON_UPLOAD_EVENT, $this->path, 'MyClassCustomWidgetUploadDispatcher', 'onFileUpload', $this->name); |
| 608 | $fileUpload->style = 'display:inline;'; |
| 609 | $this->add($fileUpload); |
| 610 | |
| 611 | // klasa MyClassCustomWidget musi zawierać metodę setFileData zgodnie z MyClassCustomWidgetUploadDispatcher::onFileUpload |
| 612 | |
| 613 | public function onFileUpload($data) { |
| 614 | |
| 615 | $filePath = $data[0]; |
| 616 | $fileName = $data[1]; |
| 617 | |
| 618 | // tutaj możemy wykonywać operacje związane z plikiem |
| 619 | |
| 620 | } |
| 621 | |
| 622 | // druga klasa z tym samym pliku |
| 623 | final class MyClassCustomWidgetUploadDispatcher { |
| 624 | |
| 625 | |
| 626 | |
| 627 | public function __construct($name) { |
| 628 | |
| 629 | $this->name = $name; |
| 630 | |
| 631 | } |
| 632 | |
| 633 | |
| 634 | |
| 635 | public function onFileUpload($fileUploader) { |
| 636 | |
| 637 | if ($uf = $fileUploader->getUploadedFile()) { |
| 638 | $o = new MyClassCustomWidgetUploadDispatcher($this->name, FALSE, FALSE, FALSE); |
| 639 | $o->setFileData($uf); |
| 640 | } |
| 641 | |
| 642 | } |
| 643 | |
| 644 | } |
| 645 | |
| 646 | }}} |