Exemplo n.º 1
0
 public function index05Action()
 {
     if ($this->request->isPost()) {
         $upload = new \ZendVN\File\Upload();
         $fileName = $upload->getFileName();
         $upload->addValidator("Extension", true, array("png", "jpg"), "image")->addValidator("Size", false, array("min" => "100KB", "max" => "1MB"), "zip");
         foreach ($fileName as $key => $value) {
             if ($upload->isValid($key)) {
                 $prefix = $key == "image" ? "img_" : "file_";
                 $upload->uploadFile($key, FILES_PATH . $key, array("task" => "rename"), $prefix);
             } else {
                 $message = $upload->getMessages();
                 echo "<pre style='font-weight:bold'>";
                 print_r($message);
                 echo "</pre>";
             }
         }
     }
 }
 public function multiDeleteAction()
 {
     if (!empty($this->_arrParam['id'])) {
         $arrParam = explode(",", $this->_arrParam['id']);
         $items = $this->getTable()->deleteItem($arrParam, array('task' => 'list-images'));
         //if(!empty($items)){
         foreach ($items as $item) {
             $upload = new \ZendVN\File\Upload();
             $upload->removeFile(UPLOAD_PATH . '/gallery/' . $item->images);
         }
         //}
         $this->getTable()->deleteItem($arrParam, array('task' => 'multi-delete-item'));
         $this->flashMessenger()->addSuccessMessage('Dữ liệu đã được xóa thành công');
     }
     $this->redirect()->toUrl('/admin/gallery/');
     return $this->getResponse();
 }
Exemplo n.º 3
0
 public function uploadBackgroundAction()
 {
     $view = new ViewModel();
     $dataItems = null;
     $dataPaginator = null;
     $isXmlHttpRequest = false;
     //Disable Layout
     if ($this->getRequest()->isXmlHttpRequest() == true) {
         $isXmlHttpRequest = true;
         if ($this->getRequest()->isPost()) {
             $upload = new \ZendVN\File\Upload();
             $upload->addValidator('Extension', true, array('png', 'jpg'), 'image');
             $upload->addValidator('Size', false, array('min' => '1kb', 'max' => '500kb'), 'image');
             if ($upload->isValid('image')) {
                 //upload ảnh mới
                 $fileName = $upload->uploadFile('image', UPLOAD_PATH . '/skin/', array('task' => 'rename'), 'batdongsan_');
                 //Thực hiện xóa ảnh cũ
                 $item = $this->getTable()->getItem($this->_arrParam, array('task' => 'get-item'));
                 $arrConfig = \Zend\Json\Json::decode($item->config_background);
                 foreach ($arrConfig->listBackground as $key => $item) {
                     $arrBackground['listBackground'][] = array('name' => $item->name, 'type' => $item->type);
                 }
                 $arrBackground['listBackground'][] = array('name' => $fileName, 'type' => 'system');
                 $arrBackground['curentBackground'] = array('background' => $arrConfig->curentBackground->background, 'style' => $arrConfig->curentBackground->style);
                 //Chống tấn công XSS
                 $purifier = new \HTMLPurifier_HTMLPurifier();
                 $arrParam = array('id' => 1, 'config_background' => \Zend\Json\Json::encode($arrBackground));
                 $this->getTable()->saveItem($arrParam, array('task' => 'edit'));
             } else {
                 $fileName = $this->_arrPost['image_hidden'];
                 $messages = $upload->getMessages();
                 if (!empty($messages['fileExtensionFalse'])) {
                     echo '<script>alert("Định dạng file không hợp lệ");</script>';
                 }
                 if (!empty($messages['fileSizeTooBig'])) {
                     echo '<script>alert("Kích thước file quá lớn");</script>';
                 }
                 if (!empty($messages['fileSizeTooSmall'])) {
                     echo '<script>alert("Kích thước file quá nhỏ");</script>';
                 }
             }
         }
     }
     $view->setVariables(array('isXmlHttpRequest' => $isXmlHttpRequest, 'fileName' => $fileName, 'arrParam' => $this->_arrParam, 'currentController' => $this->_currentController));
     $view->setTerminal(true);
     return $view;
 }
 public function uploadAction()
 {
     $view = new ViewModel();
     $dataItems = null;
     $dataPaginator = null;
     $isXmlHttpRequest = false;
     //Disable Layout
     if ($this->getRequest()->isXmlHttpRequest() == true) {
         $isXmlHttpRequest = true;
         if ($this->getRequest()->isPost()) {
             $upload = new \ZendVN\File\Upload();
             $upload->addValidator('Extension', true, array('png', 'jpg'), 'image');
             $upload->addValidator('Size', false, array('min' => '1kb', 'max' => '500kb'), 'image');
             if ($upload->isValid('image')) {
                 //upload ảnh mới
                 $fileName = $upload->uploadFile('image', UPLOAD_PATH . '/logo-business/', array('task' => 'rename'), 'batdongsan_');
                 //Thực hiện xóa ảnh cũ
                 $upload->removeFile(UPLOAD_PATH . '/logo-business/' . $this->_arrPost['image_hidden']);
                 //update database
                 $arrParam = array('id' => $this->_arrPost['id'], 'logo' => $fileName);
                 $this->getTable()->saveItem($arrParam, array('task' => 'edit'));
             } else {
                 $fileName = $this->_arrPost['image_hidden'];
                 $messages = $upload->getMessages();
                 if (!empty($messages['fileExtensionFalse'])) {
                     echo '<script>alert("Định dạng file không hợp lệ");</script>';
                 }
                 if (!empty($messages['fileSizeTooBig'])) {
                     echo '<script>alert("Kích thước file quá lớn");</script>';
                 }
                 if (!empty($messages['fileSizeTooSmall'])) {
                     echo '<script>alert("Kích thước file quá nhỏ");</script>';
                 }
             }
         }
     }
     $view->setVariables(array('isXmlHttpRequest' => $isXmlHttpRequest, 'fileName' => $fileName, 'arrParam' => $this->_arrParam, 'currentController' => $this->_currentController));
     $view->setTerminal(true);
     return $view;
 }
 public function deleteAction()
 {
     if (!empty($this->_arrParam['id'])) {
         $filter = new \Zend\Filter\Digits();
         $id = $filter->filter($this->_arrParam['id']);
         $arrParam = array('id' => $id);
         $item = $this->getTable()->getItem($this->_arrParam, array('task' => 'get-item'));
         //không thể xóa tài khoản admin
         if ($item->group_id != 1) {
             $upload = new \ZendVN\File\Upload();
             $upload->removeFile(UPLOAD_PATH . '/avatar/' . $item->avatar);
             $this->getTable()->deleteItem($arrParam, array('task' => 'delete-item'));
         }
         $this->flashMessenger()->addSuccessMessage('Dữ liệu đã được xóa thành công');
     }
     $this->redirect()->toUrl('/user/account/staff/');
     return $this->getResponse();
 }
 public function deleteAction()
 {
     if (!empty($this->_arrParam['id'])) {
         $filter = new \Zend\Filter\Digits();
         $id = $filter->filter($this->_arrParam['id']);
         $arrParam = array('id' => $id);
         $item = $this->getTable()->getItem($this->_arrParam, array('task' => 'get-item'));
         $upload = new \ZendVN\File\Upload();
         $images = \Zend\Json\Json::decode($item->images);
         if (!empty($images)) {
             foreach ($images as $image) {
                 $upload->removeFile(UPLOAD_PATH . '/real-estate/' . $image);
             }
         }
         $this->getTable()->deleteItem($arrParam, array('task' => 'delete-item'));
         $this->flashMessenger()->addSuccessMessage('Dữ liệu đã được xóa thành công');
     }
     $this->redirect()->toUrl('/user/real-estate/');
     return $this->getResponse();
 }
 public function multiDeleteAction()
 {
     if (!empty($this->_arrParam['id'])) {
         $items = $this->getTable()->deleteItem($this->_arrParam, array('task' => 'list-file'));
         if (!empty($items)) {
             foreach ($items as $item) {
                 $upload = new \ZendVN\File\Upload();
                 $upload->removeFile(FILE_MANAGER_PATH . '/' . $item['name_folder'] . '/' . $item['filename']);
             }
         }
         $this->getTable()->deleteItem($this->_arrParam, array('task' => 'multi-delete-item-file'));
         $this->flashMessenger()->addSuccessMessage('Dữ liệu đã được xóa thành công');
     }
     $redirect = new Container('redirect');
     $this->redirect()->toUrl($redirect->curentUrl);
     return $this->getResponse();
 }