Esempio n. 1
0
 public function addFileUploadRenameFilter($contractId)
 {
     $file = new \Crm\Model\Contract\File();
     $file->setContractId($contractId);
     $targetFolder = \Home\Service\Uri::getSavePath($file);
     if (!file_exists($targetFolder)) {
         $oldmask = umask(0);
         mkdir($targetFolder, 0777, true);
         umask($oldmask);
     }
     $this->getInputFilter()->get('fileUpload')->getFilterChain()->attach(new \Zend\Filter\File\RenameUpload(array('target' => $targetFolder, 'use_upload_name' => true, 'overwrite' => true)));
 }
Esempio n. 2
0
 /**
  * @param null|string $name
  */
 public function __construct($serviceLocator, $options = null)
 {
     parent::__construct('taskRequirement');
     $this->setServiceLocator($serviceLocator);
     $this->setAttribute('method', 'post');
     $filter = $this->getInputFilter();
     if ($options && isset($options['id']) && $options['id']) {
         $this->id = $options['id'];
     }
     $taskFile = new \Work\Model\TaskFile();
     $taskFile->setTaskId($this->id);
     $taskFile->setCreatedDateTime(DateBase::getCurrentDateTime());
     $targetFolder = Uri::getSavePath($taskFile);
     if (!file_exists($targetFolder)) {
         $oldmask = umask(0);
         mkdir($targetFolder, 0777, true);
         umask($oldmask);
     }
     $task = new Task();
     $fileUpload = new File('fileUpload');
     $this->add($fileUpload);
     $filter->add(array('name' => 'fileUpload', 'type' => '\\Zend\\InputFilter\\FileInput', 'required' => true, 'allowEmpty' => true, 'filters' => array(new \Zend\Filter\File\RenameUpload(array('target' => $targetFolder, 'use_upload_name' => true, 'overwrite' => true))), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true, 'options' => array('messages' => array('isEmpty' => 'Bạn chưa chọn file'))), array('name' => 'File\\Size', 'break_chain_on_failure' => true, 'options' => array('max' => Task::MAX_FILE_SIZE . 'MB', 'messages' => array(\Zend\Validator\File\Size::TOO_BIG => 'File upload phải < 100Mb'))), array('name' => 'File\\Extension', 'break_chain_on_failure' => true, 'options' => array('extension' => $task->getAllowExtension(), 'messages' => array(\Zend\Validator\File\Extension::FALSE_EXTENSION => 'File upload phải là file ảnh, excel, hoặc msword,pds,pdf'))))));
 }
Esempio n. 3
0
 private function uploadIdeaFile()
 {
     $form = new \Home\Form\Media\IdeaFile($this->getServiceLocator());
     if ($this->getRequest()->isPost()) {
         $dataPopulate = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getQuery()->toArray(), $this->getRequest()->getFiles()->toArray());
         $form->setData($dataPopulate);
         if ($form->isValid()) {
             $formData = $form->getData();
             $file = new \Idea\Model\File();
             $file->exchangeArray($form->getData());
             $file->setCreatedById($this->user()->getIdentity());
             $file->setCreatedDateTime(DateBase::getCurrentDateTime());
             $fileMapper = $this->getServiceLocator()->get('\\Idea\\Model\\FileMapper');
             $fileMapper->save($file);
             //=======rename file upload============
             $targetFolder = \Home\Service\Uri::getSavePath($file);
             if (!file_exists($targetFolder)) {
                 $oldmask = umask(0);
                 mkdir($targetFolder, 0777, true);
                 umask($oldmask);
             }
             rename($formData['fileUpload']['tmp_name'], $targetFolder . '/' . $file->getFileName());
             return $this->getJsonModel()->setVariables(array('code' => 1, 'data' => $form->getData()));
         } else {
             $formData = $form->getData();
             if (isset($formData['fileUpload']['tmp_name'])) {
                 @unlink($formData['fileUpload']['tmp_name']);
             }
             return $this->getJsonModel()->setVariables(array('code' => 0, 'messages' => $form->getErrorMessagesList()));
         }
     } else {
         return $this->getJsonModel()->setVariables(array('code' => 0, 'messages' => ['Dữ liệu không hợp lệ']));
     }
 }
 /**
  * @author KienNN
  * @return \Zend\View\Model\ViewModel
  * chuyển các file của thông báo về đúng thư mục của nó
  */
 public function changeanoucementfilelocationAction()
 {
     $dbSql = $this->getServiceLocator()->get('dbSql');
     $dbAdapter = $this->getServiceLocator()->get('dbAdapter');
     $select = $dbSql->select(['af' => \Company\Model\AnnouncementFileMapper::TABLE_NAME]);
     $select->join(['a' => \Company\Model\AnnouncementMapper::TABLE_NAME], 'af.announcementId=a.id', ['companyId']);
     $select->where(['filePath IS NULL']);
     $select->order(['id asc']);
     $paginatorAdapter = new \Zend\Paginator\Adapter\DbSelect($select, $dbAdapter);
     $paginator = new \Zend\Paginator\Paginator($paginatorAdapter);
     $paginator->setItemCountPerPage(200);
     $page = $this->getRequest()->getQuery('page', 1);
     $totalFile = $this->getRequest()->getQuery('totalFile', 0);
     $paginator->setCurrentPageNumber($page);
     $fileMapper = $this->getServiceLocator()->get('\\Company\\Model\\AnnouncementFileMapper');
     foreach ($paginator as $row) {
         $row = (array) $row;
         $fileModel = new \Company\Model\AnnouncementFile();
         $fileModel->exchangeArray($row);
         $filePath = DateBase::toFormat($fileModel->getCreatedDateTime(), 'Ymd');
         $fileModel->setFilePath($filePath);
         $oldSavePath = MEDIA_PATH . '/company/announcement/' . $row['companyId'] . '/' . $fileModel->getAnnouncementId() . '/' . $fileModel->getFileName();
         $tempPath = MEDIA_PATH . '/announcement/temp/' . $fileModel->getAnnouncementId() . '/' . $fileModel->getFileName();
         if (file_exists($oldSavePath)) {
             $newSavePath = Uri::getSavePath($fileModel);
             if (!file_exists($newSavePath)) {
                 $oldmask = umask(0);
                 mkdir($newSavePath, 0777, true);
                 umask($oldmask);
             }
             @copy($oldSavePath, $newSavePath . '/' . $fileModel->getFileName());
             $fileMapper->save($fileModel);
             $totalFile++;
         } elseif (file_exists($tempPath)) {
             $newSavePath = Uri::getSavePath($fileModel);
             if (!file_exists($newSavePath)) {
                 $oldmask = umask(0);
                 mkdir($newSavePath, 0777, true);
                 umask($oldmask);
             }
             @copy($oldSavePath, $newSavePath . '/' . $fileModel->getFileName());
             $fileMapper->save($fileModel);
             $totalFile++;
         }
     }
     $this->getViewModel()->setTerminal(true);
     $this->getViewModel()->setVariable('page', $page);
     $this->getViewModel()->setVariable('totalPages', $paginator->count() + 1);
     if ($page <= $paginator->count()) {
         $this->getViewModel()->setVariable('redirectUri', Uri::build('/system/tool/changeanoucementfilelocation', ['page' => $page + 1, 'totalFile' => $totalFile]));
     }
     $this->getViewModel()->setVariable('totalFile', $totalFile);
     return $this->getViewModel();
 }
 public function moveavatarAction()
 {
     $oldAvatarfiles = scandir(MEDIA_PATH . '/user/avatar/');
     $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
     $uri = new \Home\Service\Uri();
     foreach ($oldAvatarfiles as $avatarFile) {
         if ($avatarFile != '.' && $avatarFile != '..') {
             $id = explode('.', $avatarFile)[0];
             $digitValidator = new \Zend\Validator\Digits();
             if ($digitValidator->isValid($id)) {
                 $user = new \User\Model\User();
                 $user = $userMapper->get($id);
                 $user->setAvatar($avatarFile);
                 copy(MEDIA_PATH . '/user/avatar/' . $avatarFile, $uri->getSavePath($user) . $avatarFile);
                 echo '<b>OLD: </b>' . MEDIA_PATH . '/user/avatar/' . $avatarFile . '<br>';
                 echo '<b style="color:red">NEW: </b>' . $uri->getSavePath($user) . $avatarFile . '<br>';
                 $userMapper->save($user);
             }
         }
     }
     die('Xong');
 }