예제 #1
0
 /**
  * Create a ZF HTTP file transfer adapter.
  *
  * @return void
  */
 protected function _buildAdapter()
 {
     $storage = Zend_Registry::get('storage');
     $this->_adapter = new Zend_File_Transfer_Adapter_Http($this->_adapterOptions);
     $this->_adapter->setDestination($storage->getTempDir());
     // Add a filter to rename the file to something Omeka-friendly.
     $this->_adapter->addFilter(new Omeka_Filter_Filename());
 }
예제 #2
0
 private function _uploadPagepreview()
 {
     $miscConfig = Zend_Registry::get('misc');
     $configTeaserSize = $this->_helper->config->getConfig('teaserSize');
     $savePath = $this->_websiteConfig['path'] . $this->_websiteConfig['tmp'];
     $fileMime = $this->_getMimeType();
     switch ($fileMime) {
         case 'image/png':
             $newName = '.png';
             break;
         case 'image/jpg':
         case 'image/jpeg':
             $newName = '.jpg';
             $this->_helper->session->imageQualityPreview = self::PREVIEW_IMAGE_OPTIMIZE;
             break;
         case 'image/gif':
             $newName = '.gif';
             break;
         default:
             return false;
             break;
     }
     $newName = md5(microtime(1)) . $newName;
     $newImageFile = $savePath . $newName;
     $this->_uploadHandler->addFilter('Rename', array('target' => $newImageFile, 'overwrite' => true));
     $result = $this->_uploadImages($savePath, false);
     if ($result['error'] == false) {
         Tools_Image_Tools::resize($newImageFile, $configTeaserSize ? $configTeaserSize : $miscConfig['pageTeaserSize'], true);
         $result['src'] = $this->_helper->website->getUrl() . $this->_websiteConfig['tmp'] . $newName;
     }
     return $result;
 }
예제 #3
0
 /**
  * Update profile Employee
  * @return type
  */
 public function updateProfileAction()
 {
     $this->view->headTitle('Update Profile');
     $form = new Employee_Form_UpdateProfile();
     $id = (int) $this->getParam('id', '');
     if (!$id) {
         $this->_helper->redirector('list-profile');
     }
     $employeeMapper = new Employee_Model_EmployeeMapper();
     $result = $employeeMapper->findId($id);
     if (!$result) {
         $this->view->message = "Nhan vien khong ton tai";
         return;
     }
     $this->view->form = $form;
     //set up URL image
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $uploadPath = APPLICATION_PATH . '/../public/images/avatar';
     $adapter->setDestination($uploadPath);
     $adapter->addFilter('Rename', $result->getEmployeeId() . '.jpg');
     $this->view->fileName = $result->getEmployeeId() . '.jpg';
     if (!$adapter->receive()) {
         $messages = $adapter->getMessages();
     }
     $avatar = $adapter->getFileName();
     $this->_processShowForm($form, $result);
     if ($this->_processUpdateFormProfile($form)) {
         echo "Update success";
         $this->view->message = "Update success";
         $params = array('id' => $id);
         $this->_helper->redirector("show-profile", 'profile', 'employee', $params);
     }
 }
예제 #4
0
 public function changeprofileimgAction()
 {
     if ($this->getRequest()->isPost()) {
         if (!empty($_FILES['photo']['name'])) {
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination(Zend_Registry::get('profileImagesPath'));
             $files = $adapter->getFileInfo();
             $i = 1;
             foreach ($files as $file => $info) {
                 if (!$adapter->isUploaded($file)) {
                     return $this->_redirect('/profile');
                 }
                 $extension = strtolower(end(explode('.', $info['name'])));
                 $name = time() . $this->_user->id . $i++ . "." . $extension;
                 $adapter->addFilter('Rename', array('target' => Zend_Registry::get('profileImagesPath') . $name, 'overwrite' => TRUE));
                 if (!$adapter->receive($info['name'])) {
                     $this->view->error = 'There was a problem uploading the photo. Please try again later';
                     return $this->render('error');
                 }
             }
             $filename = $adapter->getFileName();
             $filename = basename($filename);
             $changes = array('photo' => $filename);
             $profileService = new Service_Profile();
             if ($edited = $profileService->editProfile($this->_user->profileid, $changes)) {
                 return $this->_redirect('/profile');
             } else {
                 $this->view->error = 'There was a problem updating your profile. Please try again later';
                 return $this->render('error');
             }
         }
     } else {
         $this->_redirect('/profile');
     }
 }
예제 #5
0
 public function uploadAjaxAction()
 {
     $this->_helper->layout->setLayout('ajax');
     $data = $this->_request->getPost();
     $extraDados = "";
     if (isset($data['id'])) {
         $extraDados = $data['id'] . '-';
     }
     $path = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'uploads';
     $upload = new Zend_File_Transfer_Adapter_Http();
     $upload->setDestination($path);
     // Returns all known internal file information
     $files = $upload->getFileInfo();
     foreach ($files as $file => $info) {
         // Se não existir arquivo para upload
         if (!$upload->isUploaded($file)) {
             print '<p class="alert alert-warning">Nenhum arquivo selecionado para upload<p>';
             continue;
         } else {
             $fileName = $extraDados . str_replace(' ', '_', strtolower($info['name']));
             // Renomeando o arquivo
             $upload->addFilter('Rename', array('target' => $path . DIRECTORY_SEPARATOR . $fileName, 'overwrite' => true));
         }
         // Validação do arquivo ?
         if (!$upload->isValid($file)) {
             print '<p class="alert alert-danger" > <b>' . $file . '</b>. Arquivo inválido </p>';
             continue;
         } else {
             if ($upload->receive($info['name'])) {
                 print '<p class="alert alert-success"> Arquivo: <b>' . $info['name'] . '</b> enviado com sucesso e renomeado para: <b>' . $fileName . '</b> </p>';
             }
         }
     }
 }
 public function uploadAction()
 {
     $project_id = $this->_request->getParam('id');
     //Validate that project belongs to user here.
     $project_helper = $this->_helper->Projects;
     if ($project_helper->isOwner($this->user_session->id, $project_id, $this->project_model)) {
         $adapter = new Zend_File_Transfer_Adapter_Http();
         foreach ($adapter->getFileInfo() as $key => $file) {
             //Get extension
             $path = split("[/\\.]", $file['name']);
             $ext = end($path);
             try {
                 $adapter->addValidator('Extension', false, array('extension' => 'jpg,gif,png', 'case' => true));
                 //Should probably use the array method below to enable overwriting
                 $new_name = md5(rand()) . '-' . $project_id . '.' . $ext;
                 //Add rename filter
                 $adapter->addFilter('Rename', UPLOAD_PATH . $new_name);
             } catch (Zend_File_Transfer_Exception $e) {
                 die($e->getMessage());
             }
             try {
                 //Store
                 if ($adapter->receive($file['name'])) {
                     $this->image_model->addOne($project_id, $new_name, $key);
                 }
             } catch (Zend_File_Transfer_Exception $e) {
                 die($e->getMessage());
             }
         }
         header("Location: /account/project/id/{$project_id}");
     } else {
         header("Location: /account");
     }
 }
예제 #7
0
 /**
  * Handle the uploaded file
  * 
  * @return string|boolean
  */
 public function handleUploadedFile()
 {
     $upload = new Zend_File_Transfer_Adapter_Http();
     $target = $this->getTargetFilename($upload->getFilename());
     $upload->addFilter(new Zend_Filter_File_Rename(array('target' => $target)));
     return $upload->receive() ? $target : false;
 }
예제 #8
0
 public function uploadphotoAction()
 {
     if ($this->getRequest()->isPost()) {
         if ($_FILES['photo']['name'][0] != '') {
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination(Zend_Registry::get('userImagesPath'));
             $files = $adapter->getFileInfo();
             $i = 1;
             foreach ($files as $file => $info) {
                 if (!$adapter->isUploaded($file)) {
                     $this->view->sendConfirm = 'Problem uploading files';
                     return $this->render('error');
                 }
                 $extension = strtolower(end(explode('.', $info['name'])));
                 $name = time() . '4' . $i . "." . $extension;
                 $i++;
                 $adapter->addFilter('Rename', array('target' => Zend_Registry::get('userImagesPath') . $name, 'overwrite' => TRUE));
                 if (!$adapter->receive($info['name'])) {
                     return $this->render('error');
                 }
             }
             $filename = $adapter->getFileName();
             $filename = basename($filename);
             $profile = array('photo' => $filename);
             if (($edited = $this->profileService->editProfile(2, $profile)) === TRUE) {
                 $this->view->profile = $this->profileService->fetchProfile(2);
             } else {
                 $this->view->profile = $edited;
             }
             $this->render('getprofile');
         }
     }
 }
예제 #9
0
 public function upload($params = array())
 {
     if (!is_dir($params['destination_folder'])) {
         mkdir($params['destination_folder'], 0777, true);
     }
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($params['destination_folder']);
     $adapter->setValidators($params['validators']);
     if ($adapter->getValidator('ImageSize')) {
         $adapter->getValidator('ImageSize')->setMessages(array('fileImageSizeWidthTooBig' => $this->_('Image too large, %spx maximum allowed.', '%maxwidth%'), 'fileImageSizeWidthTooSmall' => $this->_('Image not large enough, %spx minimum allowed.', '%minwidth%'), 'fileImageSizeHeightTooBig' => $this->_('Image too high, %spx maximum allowed.', '%maxheight%'), 'fileImageSizeHeightTooSmall' => $this->_('Image not high enough, %spx minimum allowed.', '%minheight%'), 'fileImageSizeNotDetected' => $this->_("The image size '%s' could not be detected.", '%value%'), 'fileImageSizeNotReadable' => $this->_("The image '%s' does not exist", '%value%')));
     }
     if ($adapter->getValidator('Size')) {
         $adapter->getValidator('Size')->setMessages(array('fileSizeTooBig' => $this->_("Image too large, '%s' allowed.", '%max%'), 'fileSizeTooSmall' => $this->_("Image not large enough, '%s' allowed.", '%min%'), 'fileSizeNotFound' => $this->_("The image '%s' does not exist", '%value%')));
     }
     if ($adapter->getValidator('Extension')) {
         $adapter->getValidator('Extension')->setMessages(array('fileExtensionFalse' => $this->_("Extension not allowed, '%s' only", '%extension%'), 'fileExtensionNotFound' => $this->_("The file '%s' does not exist", '%value%')));
     }
     $files = $adapter->getFileInfo();
     $return_file = '';
     foreach ($files as $file => $info) {
         //Créé l'image sur le serveur
         if (!$adapter->isUploaded($file)) {
             throw new Exception($this->_('An error occurred during process. Please try again later.'));
         } else {
             if (!$adapter->isValid($file)) {
                 if (count($adapter->getMessages()) == 1) {
                     $erreur_message = $this->_('Error : <br/>');
                 } else {
                     $erreur_message = $this->_('Errors : <br/>');
                 }
                 foreach ($adapter->getMessages() as $message) {
                     $erreur_message .= '- ' . $message . '<br/>';
                 }
                 throw new Exception($erreur_message);
             } else {
                 $new_name = uniqid("file_");
                 if (isset($params['uniq']) and $params['uniq'] == 1) {
                     if (isset($params['desired_name'])) {
                         $new_name = $params['desired_name'];
                     } else {
                         $format = pathinfo($info["name"], PATHINFO_EXTENSION);
                         if (!in_array($format, array("png", "jpg", "jpeg", "gif"))) {
                             $format = "jpg";
                         }
                         $new_name = $params['uniq_prefix'] . uniqid() . ".{$format}";
                     }
                     $new_pathname = $params['destination_folder'] . '/' . $new_name;
                     $adapter->addFilter(new Zend_Filter_File_Rename(array('target' => $new_pathname, 'overwrite' => true)));
                 }
                 $adapter->receive($file);
                 $return_file = $new_name;
             }
         }
     }
     return $return_file;
 }
예제 #10
0
 public function uploadAction()
 {
     if (!empty($_FILES)) {
         try {
             $path = '/var/apps/iphone/';
             $base_path = Core_Model_Directory::getBasePathTo($path);
             $filename = uniqid() . '.pem';
             if (!is_dir($base_path)) {
                 mkdir($base_path, 0775, true);
             }
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination($base_path);
             $adapter->setValidators(array('Extension' => array('pem', 'case' => false)));
             $adapter->getValidator('Extension')->setMessages(array('fileExtensionFalse' => $this->_("Extension not allowed, \\'%s\\' only", '%extension%')));
             $files = $adapter->getFileInfo();
             foreach ($files as $file => $info) {
                 if (!$adapter->isUploaded($file)) {
                     throw new Exception($this->_('An error occurred during process. Please try again later.'));
                 } else {
                     if (!$adapter->isValid($file)) {
                         if (count($adapter->getMessages()) == 1) {
                             $erreur_message = $this->_('Error : <br/>');
                         } else {
                             $erreur_message = $this->_('Errors : <br/>');
                         }
                         foreach ($adapter->getMessages() as $message) {
                             $erreur_message .= '- ' . $message . '<br/>';
                         }
                         throw new Exception($erreur_message);
                     } else {
                         $adapter->addFilter(new Zend_Filter_File_Rename(array('target' => $base_path . $filename, 'overwrite' => true)));
                         $adapter->receive($file);
                     }
                 }
             }
             $certificat = new Push_Model_Certificat();
             $certificat->find('ios', 'type');
             if (!$certificat->getId()) {
                 $certificat->setType('ios');
             }
             $certificat->setPath($path . $filename)->save();
             $datas = array('success' => 1, 'files' => 'eeeee', 'message_success' => $this->_('Infos successfully saved'), 'message_button' => 0, 'message_timeout' => 2);
         } catch (Exception $e) {
             $datas = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($datas));
     }
 }
예제 #11
0
 public function imageAction()
 {
     if ($this->getRequest()->isPost()) {
         $upload = new Zend_File_Transfer_Adapter_Http();
         $dirs = array('image' => array('gif', 'jpg', 'jpeg', 'png'), 'flash' => array('swf', 'flv'));
         $dir = $this->_getParam('dir');
         if (!isset($dirs[$dir])) {
             $this->_alert('上传类型出错!');
         }
         $savePath = UPLOAD_PATH . DS . $dir;
         //检查文件大小
         $upload->addValidator('Size', false, 500000);
         if (false == $upload->isValid()) {
             $this->_alert('上传文件大小超过500KB限制。');
         }
         //检查目录
         if (@is_dir($savePath) === false) {
             $this->_alert('上传目录不存在。');
         }
         //检查目录写权限
         if (@is_writable($savePath) === false) {
             $this->_alert('上传目录没有写权限。');
         }
         //获得文件类型
         $upload->addValidator('Extension', false, $dirs[$dir]);
         if (false == $upload->isValid()) {
             $this->_alert('只能上传' . implode('、', $dirs[$dir]) . '文件类型');
         }
         //设置保存的Path
         $upload->setDestination($savePath);
         //设置新的文件名
         $fileInfo = $upload->getFileInfo();
         $tmpFile = $fileInfo['imgFile']['name'];
         $extension = explode('.', $tmpFile);
         $extension = array_pop($extension);
         $newFile = md5($tmpFile . uniqid()) . '.' . $extension;
         $upload->addFilter('Rename', array('target' => $savePath . DS . $newFile, 'overwrite' => true));
         //保存文件
         $upload->receive();
         //返回文件url
         echo Zend_Json::encode(array('error' => 0, 'url' => $this->view->baseUrl() . '/uploads/image/' . $newFile));
         exit;
     } else {
         $this->_alert('请选择文件。');
         exit;
     }
 }
예제 #12
0
 public function save($path, $extension, $userid = 0)
 {
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($path);
     $files = $adapter->getFileInfo();
     foreach ($files as $file => $info) {
         if (!$adapter->isUploaded($file)) {
             return false;
         }
         $filename = $this->generateFileName($extension, $userid);
         $adapter->addFilter('Rename', array('target' => $path . $filename, 'overwrite' => TRUE));
         if (!$adapter->receive($info['name'])) {
             return false;
         }
     }
     $filename = $adapter->getFileName();
     $filename = basename($filename);
     return $filename;
 }
예제 #13
0
 public function uploadAction()
 {
     $this->disableMvc(true, true);
     $account = new Model_Account();
     $adapter = new Zend_File_Transfer_Adapter_Http();
     if (!is_dir(ROOT_PATH . '/public/files/tmp/')) {
         mkdir(ROOT_PATH . '/public/files/tmp/');
     }
     $adapter->setDestination(ROOT_PATH . '/public/files/tmp/');
     $info = $adapter->getFileInfo();
     $ex = explode('.', $info['Filedata']['name']);
     $fileType = $ex[count($ex) - 1];
     $hash = $adapter->getHash('md5');
     $tmpFile = $info['Filedata']['destination'] . '/' . $hash . '.' . $fileType;
     $adapter->addFilter('Rename', array('target' => $tmpFile, 'overwrite' => true));
     if ($adapter->receive()) {
         $img = new Unodor_Image_Resize($tmpFile);
         $img->adaptiveResize(50, 50)->save($tmpFile, false);
         echo $hash . '.' . $fileType;
     }
 }
예제 #14
0
 /**
  * 上传图片处理方法,
  * 还有中文bug
  */
 public function upload($fileDir, $imgpath)
 {
     $adapter = new Zend_File_Transfer_Adapter_Http();
     // 不需要渲染模板页
     $this->getFrontController()->setParam('noViewRenderer', true);
     // 你存放上传文件的文件夹
     $adapter->setDestination($fileDir);
     $adapter->addValidator('Extension', false, 'gif,jpeg,png,jpg');
     //设置上传文件的后缀名
     $adapter->addValidator('Count', false, array('min' => 1, 'max' => 5));
     //设置上传文件的个数
     $adapter->addValidator('ImageSize', false, array('minwidth' => 0, 'maxwidth' => 40960, 'minhight' => 0, 'maxhight' => 40960));
     ////设置上传图片的大小
     $adapter->addValidator('FilesSize', false, array('min' => '4KB', 'max' => '4096KB'));
     ////设置上传文件的大小
     //添加过滤器来修改上传文件的名称
     if ($imgpath) {
         $adapter->addFilter('Rename', array('target' => $imgpath, 'overwrite' => true));
     }
     /* $fileInfo = $this->adapter->getFileInfo();
        foreach ($fileInfo as $file=>$info) {   //file-文件名
            if ($this->adapter->isValid($file)) {
                var_dump($info);die;
            }
        } */
     // 返回上传后出现在信息
     if (!$adapter->receive()) {
         /* $messages = $adapter->getMessages ();
            echo implode ( "n", $messages ); */
         $out[Response::ERRNO] = 0;
         $out[Response::MSG] = '上传成功!';
         Response::out($out);
         exit;
     } else {
         $out[Response::ERRNO] = 1;
         $out[Response::MSG] = '上传失败!';
         Response::out($out);
         exit;
     }
 }
예제 #15
0
 /**
  * Enter description here ...
  */
 public function saveAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $post = $this->getRequest()->getPost();
     $data = array('name' => $post['name'], 'alias' => $post['alias'], 'link' => $post['link'], 'sort' => $post['sort'], 'description' => $post['desc']);
     if (isset($post['active'])) {
         $data['active'] = 1;
     }
     if ($_FILES['icon']['name'] != '') {
         $upload = new Zend_File_Transfer_Adapter_Http();
         $upload->setDestination($_SERVER['DOCUMENT_ROOT'] . "/upload/icons/");
         $name = $upload->getFileName('icon', false);
         $ext = split("\\.", $name);
         $newName = md5($name) . '.' . $ext[count($ext) - 1];
         $upload->addFilter('Rename', array('target' => $_SERVER['DOCUMENT_ROOT'] . "/upload/icons/" . $newName, 'overwrite' => true));
         try {
             $upload->receive();
             $data['logo'] = $newName;
         } catch (Zend_File_Transfer_Exception $e) {
             $e->getMessage();
         }
     }
     //Zend_Debug::dump($post);
     $intro = new Intro();
     if ($post['id'] == "") {
         $intro->insertIntro($data);
     } else {
         $intro->updateIntro($data, $post['id']);
     }
     if ($post['savenew'] == 0) {
         $this->_redirect('admin/intro/show');
     } else {
         $this->_redirect('admin/intro/new');
     }
 }
예제 #16
0
 /**
  *
  * @return array 
  */
 public function uploadFiles()
 {
     $return = array('files' => array());
     try {
         $dir = $this->getDirDocs();
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $adapter->setDestination($dir);
         $typeValidator = new Zend_Validate_File_Extension($this->_extensions);
         $sizeFile = new Zend_Validate_File_Size($this->_maxSize);
         $adapter->addValidator($typeValidator, true)->addValidator($sizeFile, true);
         $files = $adapter->getFileInfo();
         foreach ($files as $file => $info) {
             if (!$adapter->isUploaded($file)) {
                 continue;
             }
             $name = $this->_getNewFileName($dir, $info['name']);
             $fileInfo = array('size' => $info['size'], 'name' => $name);
             if (!$adapter->isValid($file)) {
                 $messages = $adapter->getMessages();
                 $fileInfo['error'] = array_shift($messages);
                 $return['files'][] = $fileInfo;
                 continue;
             }
             $adapter->addFilter('Rename', $dir . $name, $file);
             $adapter->receive($file);
             $pathFile = $this->publicFileUrl($dir . $name);
             $fileInfo['url'] = $pathFile;
             $fileInfo['delete_url'] = '/client/document/delete/?file=' . $pathFile;
             $fileInfo['delete_type'] = 'DELETE';
             $return['files'][] = $fileInfo;
         }
         return $return;
     } catch (Exception $e) {
         return $return;
     }
 }
예제 #17
0
 public function addAction()
 {
     // action body
     $cat_arr = $this->getCategoriesArray();
     $prodform = new Application_Form_Product();
     $catName = $prodform->getElement('catid');
     foreach ($cat_arr as $id => $name) {
         $catName->addMultiOption($id, $name);
     }
     $this->view->prodform = $prodform;
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getAllParams())) {
             $new_image_name = time() . '_' . $this->getParam('name');
             $upload = new Zend_File_Transfer_Adapter_Http();
             $upload->addFilter('Rename', APPLICATION_PATH . '/../public/img/product/' . $new_image_name);
             $upload->receive();
             $form_data = $form->getValues();
             $model = new Application_Model_Product();
             $form_data['picture'] = $new_image_name;
             $da = $model->addProduct($form_data);
             $this->redirect('Product/list');
         }
     }
 }
예제 #18
0
 /**
  * 上传头像
  */
 public function updateavatarAction()
 {
     //这种方式能得到urid
     $urid = $_GET['urid'];
     $imgName = md5($urid) . '.jpg';
     $fileDir = __PUBLIC__ . '/upload/image/avatar/';
     //ImgUploadController::upload($fileDir, $imgpath);
     $adapter = new Zend_File_Transfer_Adapter_Http();
     // 不需要渲染模板页
     $this->getFrontController()->setParam('noViewRenderer', true);
     // 你存放上传文件的文件夹
     $adapter->setDestination($fileDir);
     $adapter->addValidator('Extension', false, 'gif,jpeg,png,jpg');
     //设置上传文件的后缀名
     $adapter->addValidator('Count', false, array('min' => 1, 'max' => 5));
     //设置上传文件的个数
     $adapter->addValidator('ImageSize', false, array('minwidth' => 0, 'maxwidth' => 40960, 'minhight' => 0, 'maxhight' => 40960));
     ////设置上传图片的大小
     $adapter->addValidator('FilesSize', false, array('min' => '4KB', 'max' => '4096KB'));
     ////设置上传文件的大小
     //添加过滤器来修改上传文件的名称
     if ($imgName) {
         $adapter->addFilter('Rename', array('target' => $imgName, 'overwrite' => true));
     }
     //上传成功,把数据插入到数据库中
     $imagePath = 'http://' . gethostbyname($_ENV['COMPUTERNAME']) . '/upload/image/avatar/' . $imgName;
     $result = $this->_userCenter->updateAvatar($urid, $imagePath);
     if ($result) {
         $out[Response::ERRNO] = 0;
         $out[Response::MSG] = '上传成功!';
         Response::out($out);
         exit;
     }
     // 返回上传后出现在信息
     if (!$adapter->receive()) {
         $out[Response::ERRNO] = 0;
         $out[Response::MSG] = '上传成功!';
         Response::out($out);
         exit;
     } else {
         $out[Response::ERRNO] = 1;
         $out[Response::MSG] = '上传失败!';
         Response::out($out);
         exit;
     }
     exit;
 }
예제 #19
0
 function editpagesAction()
 {
     $system = new Admin_Model_Page();
     $paginator = Zend_Paginator::factory($system->option_page());
     $paginator->setItemCountPerPage(15);
     $paginator->setPageRange(10);
     $currentPage = $this->_request->getParam('page', 1);
     $paginator->setCurrentPageNumber($currentPage);
     $this->view->bookss = $paginator;
     if ($this->_request->isPost()) {
         $this->view->purifier = Zend_Registry::get('purifier');
         $conf = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($conf);
         $menu = $purifier->purify($this->_request->getParam('menu'));
         $dis = $purifier->purify($this->_request->getParam('dis'));
         $title = $purifier->purify($this->_request->getParam('title'));
         $key = $purifier->purify($this->_request->getParam('key'));
         $description = $purifier->purify($this->_request->getParam('description'));
         $position = $purifier->purify($this->_request->getParam('position'));
         $active = $purifier->purify($this->_request->getParam('active'));
         $home = $purifier->purify($this->_request->getParam('home'));
         $address = $purifier->purify($this->_request->getParam('address'));
         $content = stripslashes($this->_request->getParam('content'));
         $img = $purifier->purify($this->_request->getParam('images'));
         $test = $_FILES['images']['name'];
         if ($test == '') {
             $images123 = $purifier->purify($this->_request->getParam('images_hiden'));
         } else {
             $upload = new Zend_File_Transfer_Adapter_Http();
             $images = $upload->getFilename();
             $images = basename($images);
             $random_digit = rand(00, 99999);
             $img = $random_digit . $images;
             $filterRename = new Zend_Filter_File_Rename(array('target' => 'Upload/' . $img, 'overwrite' => false));
             $upload->addFilter($filterRename);
             $upload->receive();
             $img_1_2 = APPLICATION_PATH . "/../Upload/{$img}";
             $img_2 = time() . ".png";
             $img_2_2 = APPLICATION_PATH . "/../Upload/{$img_2}";
             rename($img_1_2, $img_2_2);
             $images123 = $img_2;
         }
         $id = $this->_request->getParam('id');
         $system->update_Pages($menu, $title, $dis, $key, $description, $images123, $position, $active, $content, $home, $address, $id);
     }
     $id = $this->_request->getParam('id');
     $edit = $system->list_Pages_1($id);
     $this->view->books = $edit;
     $this->view->id = $id;
 }
예제 #20
0
 public function dodajgaleriaAction($filefield)
 {
     $upload = new Zend_File_Transfer_Adapter_Http();
     $fileinfo = $upload->getFileInfo();
     $oRequest = $this->getRequest();
     if (!$oRequest->getParam('pro_id')) {
         $this->_redirect('adminn/produkty');
     }
     //walidacja pola zdjecie
     $oMimeValidator = new Zend_Validate_File_MimeType('image/jpg, image/jpeg');
     $oMimeValidator->setMessage('Zły format pliku.');
     $oUpload = new Zend_File_Transfer_Adapter_Http();
     $oUpload->addValidator($oMimeValidator);
     $oUpload->getValidator('Upload')->setMessage('Plik jest wymagany.', Zend_Validate_File_Upload::NO_FILE);
     try {
         $oConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/wizytowki.ini', 'wizytowki');
         $sWizytowkiKatalog = $oConfig->wizytowki->katalog;
         $sWizytowkaNazwa = FileNameManager::getName($sWizytowkiKatalog, $oUpload->getFileName('zdjecie', false));
         $oUpload->addFilter('Rename', $sWizytowkiKatalog . $sWizytowkaNazwa);
         $oUpload->receive($fileinfo[$filefield]['zdjecie']);
         $oGaleria = new Galeria();
         $aDane = array('gal_plik' => $sWizytowkaNazwa, 'gal_pro_id' => $oRequest->getParam('pro_id'));
         $oGaleria->insert($aDane);
     } catch (Exception $oException) {
         if ($sWizytowkaNazwa && file_exists($sWizytowkiKatalog . $sWizytowkaNazwa)) {
             unlink($sWizytowkiKatalog . $sWizytowkaNazwa);
         }
         $oRequest->setParam('error_zdjecie', 'Bład podczas zapisu.');
         return $this->_forward('dodajzdjecia');
     }
     $this->_redirect('admin/galeria?pro_id=' . $oRequest->getParam('pro_id'));
 }
예제 #21
0
 public function uploadAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $db = new Fotos();
     $album_id = $this->_request->getPost('album_id');
     $db->setAlbumId($album_id);
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination(APPLICATION_PATH . '/../data/temp');
     $upload = new Zend_File_Transfer();
     $files = $upload->getFileInfo();
     if (!file_exists(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'galeria' . DS . $album_id)) {
         mkdir(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'galeria' . DS . $album_id, 0777, true);
     }
     foreach ($files as $file => $info) {
         if ($upload->isUploaded($file)) {
             $extension = substr($info['name'], strrpos($info['name'], '.') + 1);
             $filename = 'photo_' . time() . '.' . $extension;
             $adapter->addFilter('Rename', array('target' => APPLICATION_PATH . '/../data/temp/' . $filename, 'overwrite' => true));
             $adapter->receive($info['name']);
             if (!$adapter->receive()) {
                 $messages = $adapter->getMessages();
                 echo implode("\n", $messages);
                 exit;
             }
             //setFileName::Url
             $db->setUrl($filename);
             //setCapa::false (0)
             $db->setCapa(0);
             $imanee = new Imanee\Imanee(APPLICATION_PATH . '/../data/temp/' . $filename);
             //resized
             $imanee->resize(870, 653)->write(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'galeria' . DS . $album_id . DS . 'r_' . $filename, 80);
             //full
             //$imanee->resize(1024, 768)
             //        ->write(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'galeria' . DS . $album_id . DS . 'f_' . $filename, 80);
             //thumbnail
             $imanee->thumbnail(200, 200, true)->write(ROOT_DIR . DS . 'site' . DS . 'images' . DS . 'galeria' . DS . $album_id . DS . 't_' . $filename, 60);
             unlink(APPLICATION_PATH . '/../data/temp/' . $filename);
             $data = array('url' => $db->getUrl(), 'album_id' => $db->getAlbumId(), 'capa' => $db->getCapa());
             $foto_id = $db->saveFoto($data);
             $data['foto_id'] = $foto_id;
             echo json_encode($data);
         }
     }
 }
예제 #22
0
 function editproductsAction()
 {
     $system = new Admin_Model_Products();
     if ($this->_request->isPost()) {
         $this->view->purifier = Zend_Registry::get('purifier');
         $conf = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($conf);
         $menu_id = $purifier->purify($this->_request->getParam('parent_id'));
         $title = $purifier->purify($this->_request->getParam('title'));
         $dis = $purifier->purify($this->_request->getParam('dis'));
         $key = $purifier->purify($this->_request->getParam('key'));
         $description = $purifier->purify($this->_request->getParam('description'));
         $home = $purifier->purify($this->_request->getParam('home'));
         $position = $purifier->purify($this->_request->getParam('position'));
         $active = $purifier->purify($this->_request->getParam('active'));
         $content = $purifier->purify($this->_request->getParam('content'));
         $price = $purifier->purify($this->_request->getParam('price'));
         $state = $purifier->purify($this->_request->getParam('state'));
         $sales = $purifier->purify($this->_request->getParam('sales'));
         $code = $purifier->purify($this->_request->getParam('code'));
         $members = $purifier->purify($this->_request->getParam('members'));
         $dictrict_id = $purifier->purify($this->_request->getParam('dictrict_id'));
         $type = $purifier->purify($this->_request->getParam('type'));
         $category_id = $purifier->purify($this->_request->getParam('category_id'));
         $img = $purifier->purify($this->_request->getParam('images'));
         $test = $_FILES['images']['name'];
         if ($test == '') {
             $images123 = $purifier->purify($this->_request->getParam('images_hiden'));
         } else {
             $upload = new Zend_File_Transfer_Adapter_Http();
             $images = $upload->getFilename();
             $images = basename($images);
             $random_digit = rand(00, 99999);
             $img = $random_digit . $images;
             $filterRename = new Zend_Filter_File_Rename(array('target' => 'Upload/' . $random_digit . $images, 'overwrite' => false));
             $upload->addFilter($filterRename);
             $upload->receive();
             $images123 = $img;
         }
         $id = $this->_request->getParam('id');
         $system->update_products($title, $description, $images123, $content, $menu_id, $price, $state, $sales, $dis, $key, $position, $active, $home, $code, $members, $dictrict_id, $type, $category_id, $id);
     }
     $id = $this->_request->getParam('id');
     $edit = $system->list_products_1($id);
     $this->view->books = $edit;
     $this->view->id = $this->_request->getParam('id');
     $this->view->menu_id = $this->_request->getParam('menu_id');
     $dt = new Admin_Model_Category();
     $district = $dt->option_dictrict();
     $this->view->bokk = $district;
     $menu = $dt->option_menu();
     $this->view->bookss = $menu;
     $mn = $dt->list_menu_1($this->_request->getParam('menu_id'));
     $this->view->book_s = $mn;
 }
 /**
  * Validate user input for option
  *
  * @throws Mage_Core_Exception
  * @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
  * @return Mage_Catalog_Model_Product_Option_Type_Default
  */
 public function validateUserValue($values)
 {
     AO::getSingleton('checkout/session')->setUseNotice(false);
     $this->setIsValid(true);
     $option = $this->getOption();
     // Set option value from request (Admin/Front reorders)
     if (isset($values[$option->getId()]) && is_array($values[$option->getId()])) {
         if (isset($values[$option->getId()]['order_path'])) {
             $orderFileFullPath = AO::getBaseDir() . $values[$option->getId()]['order_path'];
         } else {
             $this->setUserValue(null);
             return $this;
         }
         $ok = is_file($orderFileFullPath) && is_readable($orderFileFullPath) && isset($values[$option->getId()]['secret_key']) && substr(md5(file_get_contents($orderFileFullPath)), 0, 20) == $values[$option->getId()]['secret_key'];
         $this->setUserValue($ok ? $values[$option->getId()] : null);
         return $this;
     } elseif ($this->getProduct()->getSkipCheckRequiredOption()) {
         $this->setUserValue(null);
         return $this;
     }
     /**
      * Upload init
      */
     $upload = new Zend_File_Transfer_Adapter_Http();
     $file = 'options_' . $option->getId() . '_file';
     try {
         $runValidation = $option->getIsRequire() || $upload->isUploaded($file);
         if (!$runValidation) {
             $this->setUserValue(null);
             return $this;
         }
         $fileInfo = $upload->getFileInfo($file);
         $fileInfo = $fileInfo[$file];
     } catch (Exception $e) {
         $this->setIsValid(false);
         AO::throwException(AO::helper('catalog')->__("Files upload failed"));
     }
     /**
      * Option Validations
      */
     // Image dimensions
     $_dimentions = array();
     if ($option->getImageSizeX() > 0) {
         $_dimentions['maxwidth'] = $option->getImageSizeX();
     }
     if ($option->getImageSizeY() > 0) {
         $_dimentions['maxheight'] = $option->getImageSizeY();
     }
     if (count($_dimentions) > 0) {
         $upload->addValidator('ImageSize', false, $_dimentions);
     }
     // File extension
     $_allowed = $this->_parseExtensionsString($option->getFileExtension());
     if ($_allowed !== null) {
         $upload->addValidator('Extension', false, $_allowed);
     } else {
         $_forbidden = $this->_parseExtensionsString($this->getConfigData('forbidden_extensions'));
         if ($_forbidden !== null) {
             $upload->addValidator('ExcludeExtension', false, $_forbidden);
         }
     }
     /**
      * Upload process
      */
     $this->_initFilesystem();
     if ($upload->isUploaded($file) && $upload->isValid($file)) {
         $extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
         $fileName = Varien_File_Uploader::getCorrectFileName($fileInfo['name']);
         $dispersion = Varien_File_Uploader::getDispretionPath($fileName);
         $filePath = $dispersion;
         $destination = $this->getQuoteTargetDir() . $filePath;
         $this->_createWriteableDir($destination);
         $upload->setDestination($destination);
         $fileHash = md5(file_get_contents($fileInfo['tmp_name']));
         $filePath .= DS . $fileHash . '.' . $extension;
         $fileFullPath = $this->getQuoteTargetDir() . $filePath;
         $upload->addFilter('Rename', array('target' => $fileFullPath, 'overwrite' => true));
         if (!$upload->receive()) {
             $this->setIsValid(false);
             AO::throwException(AO::helper('catalog')->__("File upload failed"));
         }
         $_imageSize = @getimagesize($fileFullPath);
         if (is_array($_imageSize) && count($_imageSize) > 0) {
             $_width = $_imageSize[0];
             $_height = $_imageSize[1];
         } else {
             $_width = 0;
             $_height = 0;
         }
         $this->setUserValue(array('type' => $fileInfo['type'], 'title' => $fileInfo['name'], 'quote_path' => $this->getQuoteTargetDir(true) . $filePath, 'order_path' => $this->getOrderTargetDir(true) . $filePath, 'fullpath' => $fileFullPath, 'size' => $fileInfo['size'], 'width' => $_width, 'height' => $_height, 'secret_key' => substr($fileHash, 0, 20)));
     } elseif ($upload->getErrors()) {
         $errors = array();
         foreach ($upload->getErrors() as $errorCode) {
             if ($errorCode == Zend_Validate_File_ExcludeExtension::FALSE_EXTENSION) {
                 $errors[] = AO::helper('catalog')->__("The file '%s' for '%s' has an invalid extension", $fileInfo['name'], $option->getTitle());
             } elseif ($errorCode == Zend_Validate_File_Extension::FALSE_EXTENSION) {
                 $errors[] = AO::helper('catalog')->__("The file '%s' for '%s' has an invalid extension", $fileInfo['name'], $option->getTitle());
             } elseif ($errorCode == Zend_Validate_File_ImageSize::WIDTH_TOO_BIG || $errorCode == Zend_Validate_File_ImageSize::WIDTH_TOO_BIG) {
                 $errors[] = AO::helper('catalog')->__("Maximum allowed image size for '%s' is %sx%s px.", $option->getTitle(), $option->getImageSizeX(), $option->getImageSizeY());
             }
         }
         if (count($errors) > 0) {
             $this->setIsValid(false);
             AO::throwException(implode("\n", $errors));
         }
     } else {
         $this->setIsValid(false);
         AO::throwException(AO::helper('catalog')->__('Please specify the product required option(s)'));
     }
     return $this;
 }
예제 #24
0
 protected function _imageUpload($input_name, $file_prefix = "file")
 {
     $adapter = new Zend_File_Transfer_Adapter_Http();
     //$adapter->addValidator('Extension', false, 'jpg,png,gif');
     defined('PUBLIC_PATH') || define('PUBLIC_PATH', realpath(dirname(dirname(dirname(dirname(dirname(__FILE__)))))));
     $files = $adapter->getFileInfo();
     //echo "<pre>";
     //print_r($adapter);
     //echo "</pre>";
     $uniqId = time();
     foreach ($files as $file => $info) {
         $newFilename = false;
         if ($file == $input_name and strlen($info["name"]) > 0) {
             $adapter->setDestination(PUBLIC_PATH . "/public/items_images/");
             $originalFilename = pathinfo($adapter->getFileName($file));
             //$extesion = $file["extension"];
             $newFilename = $file_prefix . '-' . $uniqId . '.' . $originalFilename['extension'];
             $adapter->addFilter('Rename', $newFilename, $file);
             $adapter->receive($file);
             //        $products->__set("product_thumbnail",$newFilename);
         }
         return $newFilename;
     }
 }
 public function importAction()
 {
     $this->_requireAccess('editor.collections', 'manage');
     $collection = $this->_getCollection();
     if ($collection->OAI_baseURL) {
         $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(_('Since this collection has an OAI Server as source, you can not upload files for import.'));
         $this->_helper->redirector('edit', null, null, array('collection' => $collection->code));
         return;
     }
     $form = $collection->getUploadForm();
     $formData = $this->_request->getPost();
     if ($form->isValid($formData)) {
         $upload = new Zend_File_Transfer_Adapter_Http();
         $path = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('upload_path');
         $tenant_path = $path . '/' . $collection->tenant;
         if (!is_dir($tenant_path)) {
             if (!@mkdir($tenant_path, 0777, true)) {
                 $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(_('Failed to create upload folder'));
                 $this->_helper->redirector('edit', null, null, array('collection' => $collection->code));
                 return;
             }
         }
         try {
             $fileName = uniqid() . '_' . $_FILES['xml']['name'];
             $upload->addFilter('Rename', array('target' => $tenant_path . '/' . $fileName, 'overwrite' => false))->receive();
         } catch (Zend_File_Transfer_Exception $e) {
             $form->getElement('xml')->setErrors(array($e->getMessage()));
             return $this->_forward('edit');
         } catch (Zend_Filter_Exception $e) {
             $form->getElement('xml')->setErrors(array(_('A file with that name is already scheduled for import. Please delete the job if you want to import it again.')));
             return $this->_forward('edit');
         }
         $model = new OpenSKOS_Db_Table_Jobs();
         $fileinfo = $upload->getFileInfo('xml');
         $parameters = array('name' => $fileName, 'type' => $fileinfo['xml']['type'], 'size' => $fileinfo['xml']['size'], 'destination' => $fileinfo['xml']['destination'], 'deletebeforeimport' => (int) $formData['deletebeforeimport'] == 1, 'status' => $formData['status'], 'ignoreIncomingStatus' => (int) $formData['ignoreIncomingStatus'] == 1, 'lang' => $formData['lang'], 'toBeChecked' => (int) $formData['toBeChecked'] == 1, 'purge' => (int) $formData['purge'] == 1, 'onlyNewConcepts' => (int) $formData['onlyNewConcepts'] == 1, 'useUriAsIdentifier' => (int) $formData['useUriAsIdentifier'] == 1);
         $job = $model->fetchNew()->setFromArray(array('collection' => $collection->id, 'user' => Zend_Auth::getInstance()->getIdentity()->id, 'task' => OpenSKOS_Db_Table_Row_Job::JOB_TASK_IMPORT, 'parameters' => serialize($parameters), 'created' => new Zend_Db_Expr('NOW()')))->save();
     } else {
         return $this->_forward('edit');
     }
     $this->getHelper('FlashMessenger')->addMessage(_('An import job is scheduled'));
     $this->_helper->redirector('edit', null, null, array('collection' => $collection->code));
 }
예제 #26
0
 public function editAction()
 {
     $user_id = $this->getRequest()->getParam('user_id');
     $auth = Zend_Auth::getInstance()->getIdentity();
     $roleName = $auth->role;
     $uploadDir = Zend_Registry::get('config')->upload_dir . "/image/";
     //$uploadDir = APPLICATION_PATH.'/../public/uploads/image/';
     if ($user_id != $auth->user_id) {
         $this->_helper->FlashMessenger->addMessage(array('error' => 'Access denied.'));
         $this->_redirect('/user/user/myaccount');
     }
     $userModel = new User_Model_DbTable_User();
     $row = $userModel->getUserById($user_id);
     $profileModel = new User_Model_DbTable_Profile();
     $row1 = $profileModel->getProfileByUserId($user_id);
     $accountObj = new User_Model_DbTable_Account();
     //$userName = strtok($row['user_name'], '_');
     $names = explode('_', $row['user_name']);
     $last = array_pop($names);
     $userName = implode('_', $names);
     $account = $accountObj->getAccountRowByUserName('account', 'username', $userName);
     $form = new User_Form_User_Edit();
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $data['name'] = $form->getValue('name');
             $data['address'] = $form->getValue('address');
             $data['telephone'] = $form->getValue('telephone');
             $data['twitter'] = !$form->getValue('twitter') ? $form->getValue('twitter') : '@' . preg_replace("/@/", "", $form->getValue('twitter'), 1);
             $data['first_name'] = $form->getValue('first_name');
             $data['middle_name'] = $form->getValue('middle_name');
             $data['last_name'] = $form->getValue('last_name');
             $data['email'] = $form->getValue('email');
             $data['url'] = $form->getValue('url');
             $data['disqus_comments'] = $form->getValue('disqus_comments');
             $accountObj->updateAccount($data, $userName);
             $value = $userModel->updateUser($data, $user_id);
             $profileModel->updateProfile($data, $user_id);
             if ($roleName != 'user') {
                 $upload = new Zend_File_Transfer_Adapter_Http();
                 $upload->setDestination($uploadDir);
                 $upload->addFilter(new App_Filter_File_Resize(array('width' => 150, 'height' => 100, 'keepRatio' => true)));
                 $source = $upload->getFileName();
                 if (is_string($source)) {
                     $data['file_name'] = basename($source);
                 }
                 try {
                     $upload->receive();
                     $accountObj->insertFileNameOrUpdate($data, $userName);
                 } catch (Zend_File_Transfer_Exception $e) {
                     $e->getMessage();
                 }
             }
             $this->_helper->FlashMessenger->addMessage(array('message' => 'Profile saved successfully.'));
             $this->_redirect('user/user/myaccount/user_id/' . $row->user_id);
         } else {
             $form->populate($formData);
         }
     } else {
         $form->populate($row->toArray());
         $form->populate($row1->toArray());
         if ($roleName != 'superadmin' && $roleName != 'groupadmin') {
             $form->populate($account->toArray());
         }
     }
     $this->view->form = $form;
     $identity = Zend_Auth::getInstance()->getIdentity();
     $this->_helper->layout()->setLayout('layout_wep');
     if ($identity->role == 'user') {
         $model = new Model_Wep();
         $userPermission = $model->getUserPermission($identity->user_id);
         $permission = $userPermission->hasPermission(Iati_WEP_PermissionConts::VIEW_ACTIVITIES);
         if ($permission == '0') {
             $this->view->blockManager()->disable('partial/primarymenu.phtml');
         }
         $permission = $userPermission->hasPermission(Iati_WEP_PermissionConts::ADD_ACTIVITY);
         if ($permission == '0') {
             $this->view->blockManager()->disable('partial/add-activity-menu.phtml');
         }
     }
     $this->view->blockManager()->enable('partial/dashboard.phtml');
     if ($identity->role == 'user' || $identity->role == 'admin') {
         $this->view->blockManager()->enable('partial/primarymenu.phtml');
         $this->view->blockManager()->enable('partial/add-activity-menu.phtml');
         $this->view->blockManager()->enable('partial/published-list.phtml');
         $this->view->blockManager()->enable('partial/organisation-data.phtml');
         $this->view->blockManager()->enable('partial/download-my-data.phtml');
         $this->view->blockManager()->enable('partial/usermgmtmenu.phtml');
         $this->view->blockManager()->enable('partial/uploaded-docs.phtml');
         // for role user check if the user has permission to add, publish ,if not disable menu.
         if ($identity->role == 'user') {
             $model = new Model_Wep();
             $userPermission = $model->getUserPermission($identity->user_id);
             $permission = $userPermission->hasPermission(Iati_WEP_PermissionConts::ADD_ACTIVITY);
             $publishPermission = $userPermission->hasPermission(Iati_WEP_PermissionConts::PUBLISH);
             if (!$permission) {
                 $this->view->blockManager()->disable('partial/add-activity-menu.phtml');
             }
             if (!$publishPermission) {
                 $this->view->blockManager()->disable('partial/published-list.phtml');
             }
         }
     } elseif ($identity->role == 'groupadmin') {
         $this->view->blockManager()->enable('partial/groupadmin-menu.phtml');
     } else {
         $this->view->blockManager()->enable('partial/superadmin-menu.phtml');
     }
 }
예제 #27
0
 /**
  * This function is used to upload an image after resizing it.
  * @return string On success file name,on failure error message
  */
 public static function imageUploadAfterResize()
 {
     $max_size = 250;
     // maxim size for image file, in KiloBytes
     $allowtype = array('pdf', 'docx', 'rtf', 'odx', 'doc', 'txt', 'odt');
     /** Uploading the image **/
     $rezultat = '';
     $result_status = '';
     $result_msg = '';
     $type = end(explode(".", strtolower($_FILES['form_attachment']['name'])));
     if (in_array($type, $allowtype)) {
         if ($_FILES['form_attachment']['size'] <= $max_size * 1000) {
             //File Upload
             $logo = "";
             $path = FORM_ATTACHMENT_PREVIEW_PATH;
             $upload = new Zend_File_Transfer_Adapter_Http();
             $upload->setDestination($path);
             //Constructor needs one parameter, the destination path is a good idea
             $renameFilter = new Zend_Filter_File_Rename($path);
             $files = $upload->getFileInfo();
             $logo = "";
             foreach ($files as $fileID => $fileInfo) {
                 if (!$fileInfo['name'] == '') {
                     $varaible = explode('.', $fileInfo['name']);
                     $extension = end($varaible);
                     $logo = md5(uniqid(rand(), true)) . '.' . $extension;
                     $renameFilter->addFile(array('source' => $fileInfo['tmp_name'], 'target' => $logo, 'overwrite' => true));
                 }
                 // add filters to Zend_File_Transfer_Adapter_Http
                 $upload->addFilter($renameFilter);
                 // receive all files
                 try {
                     $upload->receive();
                     //Image Resize
                     $frontobj = Zend_Controller_Front::getInstance();
                     if ($frontobj->getRequest()->getParam('form_attachment') != '') {
                         $image = new Zend_Resize($path . '/' . $logo);
                         $image->resizeImage(84, 84, 'crop');
                         $image->saveImage($path . '/' . $logo, 100);
                     }
                     //End Image Resize
                 } catch (Zend_File_Transfer_Exception $e) {
                     $rezultat = '';
                     $result_status = 'error';
                     $result_msg = $e->getMessage();
                 }
                 //upto here
                 $rezultat = $logo;
                 $result_status = 'success';
                 $result_msg = 'Uploaded Succesfully.';
             }
             //End File Upload
         } else {
             $rezultat = '';
             $result_status = 'error';
             $result_msg = 'The file exceeds the maximum permitted size ' . $max_size . ' KB.';
         }
     } else {
         $rezultat = '';
         $result_status = 'error';
         $result_msg = 'The file ' . $filename . ' has not an allowed extension.';
     }
     $result = array('result' => $result_status, 'img' => $rezultat, 'msg' => $result_msg);
     return $result;
 }
 /**
  * Accepts the form
  *
  * Takes two roundtrips:
  * - first we get a HEAD request that should be answerd with
  *   responsecode 204
  * - then we get a post that only submits $_FILES (so actual $_POST will be empty)
  *   this will be an xml file for the actuel response and optionally images and/or video
  *   proper responses are
  *      201 received and stored
  *      202 received ok, not stored
  */
 public function submissionAction()
 {
     $this->makeRosaResponse();
     if ($this->getRequest()->isHead()) {
         $this->getResponse()->setHttpResponseCode(204);
     } elseif ($this->getRequest()->isPost()) {
         //Post
         // We get $_FILES variable holding the formresults as xml and all possible
         // attachments like photo's and video's
         $upload = new \Zend_File_Transfer_Adapter_Http();
         // We should really add some validators here see http://framework.zend.com/manual/en/zend.file.transfer.validators.html
         // Returns all known internal file information
         $files = $upload->getFileInfo();
         foreach ($files as $file => $info) {
             // file uploaded ?
             if (!$upload->isUploaded($file)) {
                 print "Why haven't you uploaded the file ?";
                 continue;
             }
             // validators are ok ?
             if (!$upload->isValid($file)) {
                 print "Sorry but {$file} is not what we wanted";
                 continue;
             }
         }
         //Dit moet een filter worden (rename filter) http://framework.zend.com/manual/en/zend.file.transfer.filters.html
         $upload->setDestination($this->responseDir);
         //Hier moeten we denk ik eerst de xml_submission_file uitlezen, en daar
         //iets mee doen
         if ($upload->receive('xml_submission_file')) {
             $xmlFile = $upload->getFileInfo('xml_submission_file');
             $answerXmlFile = $xmlFile['xml_submission_file']['tmp_name'];
             $resultId = $this->processReceivedForm($answerXmlFile);
             if ($resultId === false) {
                 //form not accepted!
                 foreach ($xml->children() as $child) {
                     $log->log($child->getName() . ' -> ' . $child, \Zend_Log::ERR);
                 }
             } else {
                 //$log->log(print_r($files, true), \Zend_Log::ERR);
                 //$log->log($deviceId, \Zend_Log::ERR);
                 \MUtil_File::ensureDir($this->responseDir . 'forms/' . (int) $this->openrosaFormID . '/');
                 $upload->setDestination($this->responseDir . 'forms/' . (int) $this->openrosaFormID . '/');
                 foreach ($upload->getFileInfo() as $file => $info) {
                     if ($info['received'] != 1) {
                         //Rename to responseid_filename
                         //@@TODO: move to form subdir, for better separation
                         $upload->addFilter('Rename', $resultId . '_' . $info['name'], $file);
                     }
                 }
                 //Now receive the other files
                 if (!$upload->receive()) {
                     $messages = $upload->getMessages();
                     echo implode("\n", $messages);
                 }
                 $this->getResponse()->setHttpResponseCode(201);
                 //Form received ok
             }
         }
     }
 }
예제 #29
0
파일: File.php 프로젝트: natxetee/magento2
 /**
  * Validate uploaded file
  *
  * @throws Mage_Core_Exception
  * @return Mage_Catalog_Model_Product_Option_Type_File
  */
 protected function _validateUploadedFile()
 {
     $option = $this->getOption();
     $processingParams = $this->_getProcessingParams();
     /**
      * Upload init
      */
     $upload = new Zend_File_Transfer_Adapter_Http();
     $file = $processingParams->getFilesPrefix() . 'options_' . $option->getId() . '_file';
     $maxFileSize = $this->getFileSizeService()->getMaxFileSize();
     try {
         $runValidation = $option->getIsRequire() || $upload->isUploaded($file);
         if (!$runValidation) {
             $this->setUserValue(null);
             return $this;
         }
         $fileInfo = $upload->getFileInfo($file);
         $fileInfo = $fileInfo[$file];
         $fileInfo['title'] = $fileInfo['name'];
     } catch (Exception $e) {
         // when file exceeds the upload_max_filesize, $_FILES is empty
         if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > $maxFileSize) {
             $this->setIsValid(false);
             $value = $this->getFileSizeService()->getMaxFileSizeInMb();
             Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__("The file you uploaded is larger than %s Megabytes allowed by server", $value));
         } else {
             switch ($this->getProcessMode()) {
                 case Mage_Catalog_Model_Product_Type_Abstract::PROCESS_MODE_FULL:
                     Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Please specify the product\'s required option(s).'));
                     break;
                 default:
                     $this->setUserValue(null);
                     break;
             }
             return $this;
         }
     }
     /**
      * Option Validations
      */
     // Image dimensions
     $_dimentions = array();
     if ($option->getImageSizeX() > 0) {
         $_dimentions['maxwidth'] = $option->getImageSizeX();
     }
     if ($option->getImageSizeY() > 0) {
         $_dimentions['maxheight'] = $option->getImageSizeY();
     }
     if (count($_dimentions) > 0) {
         $upload->addValidator('ImageSize', false, $_dimentions);
     }
     // File extension
     $_allowed = $this->_parseExtensionsString($option->getFileExtension());
     if ($_allowed !== null) {
         $upload->addValidator('Extension', false, $_allowed);
     } else {
         $_forbidden = $this->_parseExtensionsString($this->getConfigData('forbidden_extensions'));
         if ($_forbidden !== null) {
             $upload->addValidator('ExcludeExtension', false, $_forbidden);
         }
     }
     // Maximum filesize
     $upload->addValidator('FilesSize', false, array('max' => $maxFileSize));
     /**
      * Upload process
      */
     $this->_initFilesystem();
     if ($upload->isUploaded($file) && $upload->isValid($file)) {
         $extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
         $fileName = Mage_Core_Model_File_Uploader::getCorrectFileName($fileInfo['name']);
         $dispersion = Mage_Core_Model_File_Uploader::getDispretionPath($fileName);
         $filePath = $dispersion;
         $fileHash = md5($this->_filesystem->read($fileInfo['tmp_name']));
         $filePath .= DS . $fileHash . '.' . $extension;
         $fileFullPath = $this->getQuoteTargetDir() . $filePath;
         $upload->addFilter('Rename', array('target' => $fileFullPath, 'overwrite' => true));
         $this->getProduct()->getTypeInstance()->addFileQueue(array('operation' => 'receive_uploaded_file', 'src_name' => $file, 'dst_name' => $fileFullPath, 'uploader' => $upload, 'option' => $this));
         $_width = 0;
         $_height = 0;
         if ($this->_filesystem->isReadable($fileInfo['tmp_name'])) {
             $_imageSize = getimagesize($fileInfo['tmp_name']);
             if ($_imageSize) {
                 $_width = $_imageSize[0];
                 $_height = $_imageSize[1];
             }
         }
         $this->setUserValue(array('type' => $fileInfo['type'], 'title' => $fileInfo['name'], 'quote_path' => $this->getQuoteTargetDir(true) . $filePath, 'order_path' => $this->getOrderTargetDir(true) . $filePath, 'fullpath' => $fileFullPath, 'size' => $fileInfo['size'], 'width' => $_width, 'height' => $_height, 'secret_key' => substr($fileHash, 0, 20)));
     } elseif ($upload->getErrors()) {
         $errors = $this->_getValidatorErrors($upload->getErrors(), $fileInfo);
         if (count($errors) > 0) {
             $this->setIsValid(false);
             Mage::throwException(implode("\n", $errors));
         }
     } else {
         $this->setIsValid(false);
         Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Please specify the product required option(s)'));
     }
     return $this;
 }
예제 #30
0
 public function uploadAction()
 {
     $this->_helper->layout->disableLayout();
     if ($this->getRequest()->isPost()) {
         $cnt = 0;
         $mapper = new Application_Model_UploadMapper();
         $upload = new Zend_File_Transfer_Adapter_Http();
         $upload->addValidator('Size', false, 20000, 'file2');
         $upload->setDestination('uploads/');
         $files = $upload->getFileInfo();
         foreach ($files as $file => $info) {
             //$transform = new Zend_Image_Transform( $image );
             $ext = end(explode(".", $info['name']));
             $uuid = uniqid();
             $upload->addFilter('Rename', array('target' => 'uploads/' . $uuid . '.' . $ext, 'overwrite' => true));
             if ($upload->isValid($file)) {
                 $upload->receive($file);
             }
             $imageSize[0] = 150;
             $imageSize[1] = 150;
             $imageSize = getimagesize('uploads/' . $uuid . '.' . $ext);
             $name = $info['name'];
             $type = $info['type'];
             $size = $info['size'];
             $file = 'uploads/' . $name;
             $_post['file'] = $file;
             $_post['name'] = $name;
             $_post['type'] = $type;
             $_post['size'] = $size;
             $_post['uuid'] = $uuid;
             $_post['width'] = $imageSize[0];
             $_post['height'] = $imageSize[1];
             $_post['ext'] = $ext;
             $htmldata[$cnt] = $_post;
             $mapper->saveall($htmldata[$cnt]);
             $cnt++;
         }
         $data = json_encode($htmldata);
         echo $data;
     }
 }