コード例 #1
0
ファイル: Upload.php プロジェクト: lchen01/STEdwards
 /**
  * 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
 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');
         }
     }
 }
コード例 #3
0
 public function uploadAction()
 {
     if ($code = $this->getRequest()->getPost("code")) {
         try {
             if (empty($_FILES) || empty($_FILES['file']['name'])) {
                 throw new Exception("No file has been sent");
             }
             $path = Core_Model_Directory::getPathTo(System_Model_Config::IMAGE_PATH);
             $base_path = Core_Model_Directory::getBasePathTo(System_Model_Config::IMAGE_PATH);
             if (!is_dir($base_path)) {
                 mkdir($base_path, 0777, true);
             }
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination($base_path);
             if ($adapter->receive()) {
                 $file = $adapter->getFileInfo();
                 $config = new System_Model_Config();
                 $config->find($code, "code");
                 $config->setValue($path . DS . $file['file']['name'])->save();
                 $message = sprintf("Your %s has been successfully saved", $code);
                 $this->_sendHtml(array("success" => 1, "message" => $this->_($message)));
             } else {
                 $messages = $adapter->getMessages();
                 if (!empty($messages)) {
                     $message = implode("\n", $messages);
                 } else {
                     $message = $this->_("An error occurred during the process. Please try again later.");
                 }
                 throw new Exception($message);
             }
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
     }
 }
コード例 #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>';
             }
         }
     }
 }
コード例 #6
0
 function configAction()
 {
     // When the form is submitted
     $form_mess = "";
     if (isset($_POST['confName'])) {
         $form_mess = $this->updateConfig($_POST, $this->db_v1, $this->view, $this->session);
         $this->config_v1 = GetConfig($this->db_v1);
         // Check whether the logo file has been transmitted
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $adapter->setDestination('images/');
         $adapter->addValidator('IsImage', false);
         if ($adapter->receive()) {
             $name = $adapter->getFileName('logo_file');
             //récupérer le nom du fichier sans avoir tout le chemin
             $name = basename($name);
             $this->db_v1->execRequete("UPDATE Config SET logo_file='{$name}'");
         }
         $config = new Config();
         $this->config = $config->fetchAll()->current();
         $this->config->putInView($this->view);
         $registry = Zend_registry::getInstance();
         $registry->set("Config", $this->config);
     }
     $this->view->config_message = $form_mess;
     $this->instantiateConfigVars($this->config_v1, $this->view);
     $this->view->setFile("content", "config.xml");
     $this->view->setFile("form_config", "form_config.xml");
     $form_mess = "";
     $this->view->messages = $form_mess;
     // N.B: the config values ar eput in the views by the Myreview controller
     echo $this->view->render("layout");
 }
コード例 #7
0
ファイル: DbServicePrice.php プロジェクト: samlanh/lynacr
 public function updateServicePrice($data)
 {
     $db = $this->getAdapter();
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $part = PUBLIC_PATH . '/images';
     $adapter->setDestination($part);
     $adapter->receive();
     $photo = $adapter->getFileInfo();
     if (!empty($photo['photo']['name'])) {
         $img = $photo['photo']['name'];
     } else {
         $img = $data['oldphoto'];
     }
     if (!empty($photo['photo1']['name'])) {
         $img1 = $photo['photo1']['name'];
     } else {
         $img1 = $data['oldphoto1'];
     }
     if (!empty($photo['photo2']['name'])) {
         $img2 = $photo['photo2']['name'];
     } else {
         $img2 = $data['oldphoto2'];
     }
     $arr = array('service_title' => $data['serice_title'], 'description' => $data['description'], 'photo' => $img, 'photo1' => $img1, 'photo2' => $img2, 'price' => $data['price'], 'date' => date("Y-m-d"), 'user_id' => $this->getUserId(), 'status' => $data['status']);
     $where = $this->getAdapter()->quoteInto("id=?", $data['id']);
     $this->update($arr, $where);
 }
コード例 #8
0
 public function uploadAction()
 {
     try {
         if (empty($_FILES) || empty($_FILES['file']['name'])) {
             throw new Exception($this->_("No file has been sent"));
         }
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $adapter->setDestination(Core_Model_Directory::getTmpDirectory(true));
         if ($adapter->receive()) {
             $file = $adapter->getFileInfo();
             $data = $this->_getPackageDetails($file['file']['tmp_name']);
         } else {
             $messages = $adapter->getMessages();
             if (!empty($messages)) {
                 $message = implode("\n", $messages);
             } else {
                 $message = $this->_("An error occurred during the process. Please try again later.");
             }
             throw new Exception($message);
         }
     } catch (Exception $e) {
         $data = array("error" => 1, "message" => $e->getMessage());
     }
     $this->_sendHtml($data);
 }
コード例 #9
0
 public function uploadAction()
 {
     try {
         if (empty($_FILES) || empty($_FILES['module']['name'])) {
             throw new Exception("No file has been sent");
         }
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $adapter->setDestination(Core_Model_Directory::getTmpDirectory(true));
         //            $adapter->addValidator('MimeType', false, 'application/zip');
         if ($adapter->receive()) {
             $file = $adapter->getFileInfo();
             $parser = new Installer_Model_Installer_Module_Parser();
             if ($parser->setFile($file['module']['tmp_name'])->check()) {
                 $infos = pathinfo($file['module']['tmp_name']);
                 $filename = $infos['filename'];
                 $this->_redirect('installer/module/install', array('module_name' => $filename));
             } else {
                 $messages = $parser->getErrors();
                 $message = implode("\n", $messages);
                 throw new Exception($this->_($message));
             }
         } else {
             $messages = $adapter->getMessages();
             if (!empty($messages)) {
                 $message = implode("\n", $messages);
             } else {
                 $message = $this->_("An error occurred during the process. Please try again later.");
             }
             throw new Exception($message);
         }
     } catch (Exception $e) {
         $this->getSession()->addError($e->getMessage());
         $this->_redirect('installer/module');
     }
 }
コード例 #10
0
 public function uploadFile($object, $type, $subtype)
 {
     $sheets = new SxModule_Sheets();
     $base = realpath(APPLICATION_PATH . '/../public_html/securedocs/');
     $path = $type . '/' . $subtype;
     if (!is_dir($base . '/' . $path)) {
         echo $base . '/' . $path;
         mkdir($base . '/' . $type);
         mkdir($base . '/' . $path);
     }
     if ($object->getFile() == null) {
         $object->setFile('');
     }
     $uploadAdapter = new Zend_File_Transfer_Adapter_Http();
     $uploadAdapter->setDestination($base . '/' . $path);
     $uploadAdapter->setOptions(array('ignoreNoFile' => true));
     $uploadAdapter->receive();
     $files = $uploadAdapter->getFileName(null, true);
     foreach ($_FILES['file']['name'] as $key => $filename) {
         if (!$filename) {
             continue;
         }
         $file = $base . '/' . $path . '/' . $filename;
         $date = date('Y-m-d His');
         $path_info = pathinfo($filename);
         $myfilename = str_replace(' ', '_', $path_info['filename'] . '_' . $date . '.' . $path_info['extension']);
         $myfilename = $sheets->createFileName($myfilename);
         $newfile = $base . '/' . $path . '/' . $myfilename;
         rename($file, $newfile);
         $object->setFile($myfilename);
     }
 }
コード例 #11
0
 public function addAction()
 {
     SxCms_Acl::requireAcl('securedocs', 'securedocs.add');
     $base = realpath(APPLICATION_PATH . '/../public_html/securedocs/');
     $path = base64_decode($this->_getParam('path'));
     if ($this->getRequest()->isPost()) {
         $uploadAdapter = new Zend_File_Transfer_Adapter_Http();
         $uploadAdapter->setDestination($base . $path);
         $uploadAdapter->setOptions(array('ignoreNoFile' => true));
         $uploadAdapter->receive();
         $files = $uploadAdapter->getFileName(null, true);
         foreach ($_FILES['file']['name'] as $key => $filename) {
             if (!$filename) {
                 continue;
             }
             $summary = $this->_getParam('samenvatting');
             $mail = $this->_getParam('mail', '');
             $file = $base . $path . '/' . $filename;
             $newfile = $base . $path . '/' . str_replace(" ", "", $filename);
             rename($file, $newfile);
             $file = new SxModule_Securedocs_File($newfile);
             $file->setPath($path);
             $file->setSummary($summary[$key]);
             $file->setMail(isset($mail[$key]) ? "1" : "0");
             $file->save();
             if ($mail[$key]) {
                 $groups = explode('/', $path);
                 $control = $path;
                 if ($control != "") {
                     $proxy = new SxModule_Securedocs_Folder_Proxy();
                     $folder = $proxy->getByFolder($groups[1]);
                     $folderId = $folder->getFolderId();
                     $proxy = new SxModule_Securedocs_Group_Proxy();
                     $groups = $proxy->getAllByMap($folderId);
                     $aantal = count($groups);
                     $q = 0;
                     $groupids = '(';
                     foreach ($groups as $group) {
                         $q++;
                         if ($q != $aantal) {
                             $groupids .= $group->getGroupId() . ",";
                         } else {
                             $groupids .= $group->getGroupId();
                         }
                     }
                     $groupids .= ')';
                     $proxy = new SxModule_Members_Proxy();
                     $members = $proxy->getAllByGroups($groupids);
                     foreach ($members as $member) {
                         $member->sendDocument($file);
                     }
                 }
             }
         }
         $this->_redirect('/admin/securedocs/index/path/' . base64_encode($path));
     }
     $this->view->path = $path;
     $this->view->messages = Sanmax_MessageStack::getInstance('SxModule_Securedocs_File');
 }
コード例 #12
0
ファイル: Uploader.php プロジェクト: bklein01/siberian_cms_2
 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;
 }
コード例 #13
0
 public function indexAction()
 {
     SxCms_Acl::requireAcl('filemanager', 'filemanager.index');
     $base = APPLICATION_PATH . '/../public_html/files/';
     $base = realpath($base);
     $path = base64_decode($this->_getParam('path'));
     if ($this->getRequest()->isPost()) {
         if (null !== $this->_getParam('folder')) {
             SxCms_Acl::requireAcl('filemanager', 'filemanager.add.folder');
             if (strlen($this->_getParam('folder'))) {
                 $dirname = $path . '/' . $this->_getParam('folder');
                 mkdir($base . $dirname);
                 $this->_redirect('/admin/filemanager/index/path/' . base64_encode($path));
             }
         } else {
             SxCms_Acl::requireAcl('filemanager', 'filemanager.add.file');
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination(realpath($base) . $path);
             if ($adapter->receive()) {
                 $filename = realpath($adapter->getFileName('filename'));
                 $file = new SxCms_File($filename);
                 $path = $file->getPathnameFromBase();
                 $nfile = $path . '/' . $file->getBasename();
                 $this->_redirect('/admin/filemanager/edit/file/' . base64_encode($nfile) . '/path/' . base64_encode($path));
             } else {
                 $msg = Sanmax_MessageStack::getInstance('SxCms_Filemanager');
                 $msg->addMessage('file', $adapter->getMessages());
             }
         }
     }
     $this->view->messages = Sanmax_MessageStack::getInstance('SxCms_Filemanager');
     try {
         $it = new SxCms_Filesystem(realpath($base . $path));
     } catch (Exception $e) {
         $it = new SxCms_Filesystem($base);
         $path = '';
         $e;
     }
     $topdir = explode('/', $path);
     if (count($topdir) > 1) {
         array_pop($topdir);
         $topdir = implode('/', $topdir);
     } else {
         $topdir = '';
     }
     $this->view->files = $it;
     $this->view->path = $path;
     $this->view->showpath = explode('/', $path);
     $this->view->topdir = $topdir;
     if ($this->_getParam('full')) {
         $this->_helper->layout->setLayout('nolayout');
         $this->view->full = true;
     }
 }
 /**
  * Processa os dados do formulário de importação de RPS [json]
  * 
  * @return void
  */
 public function rpsProcessarAction()
 {
     parent::noLayout();
     $oForm = new Contribuinte_Form_ImportacaoArquivo();
     $oForm->renderizaCamposRPS();
     // Adiciona a validação do arquivo junto ao restante das mensagens de erro do form
     $aDados = array_merge($this->getRequest()->getPost(), array('isUploaded' => $oForm->arquivo->isUploaded()));
     // Valida o formulario e processa a importação
     if ($this->getRequest()->isPost() && $oForm->arquivo->isUploaded()) {
         $oArquivoUpload = new Zend_File_Transfer_Adapter_Http();
         try {
             $oArquivoUpload->setDestination(APPLICATION_PATH . '/../public/tmp/');
             // Confirma o upload e processa o arquivo
             if ($oArquivoUpload->receive()) {
                 $oImportacaoModelo1 = new Contribuinte_Model_ImportacaoArquivoRpsModelo1();
                 $oImportacaoModelo1->setArquivoCarregado($oArquivoUpload->getFileName());
                 $oArquivoCarregado = $oImportacaoModelo1->carregar();
                 if ($oArquivoCarregado != NULL && $oImportacaoModelo1->validaArquivoCarregado()) {
                     // Valida as regras de negócio e processa a importação
                     $oImportacaoProcessamento = new Contribuinte_Model_ImportacaoArquivoProcessamento();
                     $oImportacaoProcessamento->setCodigoUsuarioLogado($this->usuarioLogado->getId());
                     $oImportacaoProcessamento->setArquivoCarregado($oArquivoCarregado);
                     // Processa a importação
                     $oImportacao = $oImportacaoProcessamento->processarImportacaoRps();
                     if ($oImportacao->getId()) {
                         $sUrlRecibo = "/contribuinte/importacao-arquivo/rps-recibo/id/{$oImportacao->getId()}";
                         $aRetornoJson['status'] = TRUE;
                         $aRetornoJson['url'] = $this->view->baseUrl($sUrlRecibo);
                         $aRetornoJson['success'] = $this->translate->_('Arquivo importado com sucesso.');
                     } else {
                         throw new Exception($this->translate->_('Ocorreu um erro ao importar o arquivo.'));
                     }
                 } else {
                     throw new Exception($oImportacaoModelo1->processaErroSistema());
                 }
             }
         } catch (DBSeller_Exception_ImportacaoXmlException $oErro) {
             $aRetornoJson['status'] = FALSE;
             $aRetornoJson['error'] = array_merge(array('<b>' . $this->translate->_('Ocorreu um erro ao importar o arquivo:') . '</b><br>'), $oErro->getErrors());
         } catch (Exception $oErro) {
             $aRetornoJson['status'] = FALSE;
             $aRetornoJson['error'][] = $oErro->getMessage();
         }
         if (is_file($oArquivoUpload->getFileName())) {
             unlink($oArquivoUpload->getFileName());
         }
     } else {
         $aRetornoJson['status'] = FALSE;
         $aRetornoJson['fields'] = array_keys($oForm->getMessages());
         $aRetornoJson['error'][] = $this->translate->_('Preencha os dados corretamente.');
     }
     echo $this->getHelper('json')->sendJson($aRetornoJson);
 }
コード例 #15
0
ファイル: DbRestore.php プロジェクト: samlanh/lynacr
 public function UploadFileDatabase($data)
 {
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination(PUBLIC_PATH);
     $fileinfo = $adapter->getFileInfo();
     $rs = $adapter->receive();
     if ($rs == 1) {
         return true;
     } else {
         return false;
     }
 }
コード例 #16
0
ファイル: FileUploader.php プロジェクト: jager/cms
 public function transferFile()
 {
     if (!is_dir($this->_path)) {
         mkdir($this->_path, 0777, true);
     }
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($this->_path);
     if (!$adapter->receive()) {
         $messages = $adapter->getMessages();
         throw new Exception(implode("<br />", $messages));
     }
     return $adapter->getFileInfo();
 }
コード例 #17
0
 protected function _imageResizeAndSave($object)
 {
     $path = APPLICATION_ROOT . '/public_html/images/topcontentblock/';
     $system->lng = $this->_getParam('lng');
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($path);
     $adapter->setOptions(array('ignoreNoFile' => true));
     if (!$adapter->receive()) {
         $msgr = Sanmax_MessageStack::getInstance('SxModule_Topcontentblock_Validator');
         $msgr->addMessage('file', $adapter->getMessages(), 'title');
     }
     if ($object->getPicture() == null) {
         $object->setPicture('');
     }
     $files = $adapter->getFileInfo();
     foreach ($files as $file) {
         if (!$file['tmp_name']) {
             continue;
         }
         $path0 = $path . "253X115/";
         $path1 = $path . "1263X575/";
         $path2 = $path . "1263X325/";
         $filename = $object->createThumbName($file['name']) . '_' . time() . '.jpg';
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(253, 115);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(100);
         $image->setImageFormat('jpeg');
         $image->writeImage($path0 . $filename);
         $image->clear();
         $image->destroy();
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(1263, 575);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(75);
         $image->setImageFormat('jpeg');
         $image->writeImage($path1 . $filename);
         $image->clear();
         $image->destroy();
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(1263, 325);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(75);
         $image->setImageFormat('jpeg');
         $image->writeImage($path2 . $filename);
         $image->clear();
         $image->destroy();
         unlink($file['tmp_name']);
         $object->setPicture($filename);
     }
 }
コード例 #18
0
ファイル: UploadHash.php プロジェクト: nandorodpires2/gallery
 /**
  * Upload Function
  *
  * Esta função faz upload do arquivo, renomeia e seta os atriutos
  * filename, filehash, filesize
  *
  * @return boolean
  */
 public function upload()
 {
     /* Verifica se ha arquivo para upload */
     $upload = new Zend_File_Transfer_Adapter_Http();
     if ($upload->isValid($this->field)) {
         $this->filename = $upload->getFileName($this->field, false);
         $this->filehash = md5(time() . microtime(true)) . "." . $this->getExtension($this->filename);
         $this->filesize = $upload->getFileSize();
         $upload->setDestination($this->path)->setFilters(array("Rename" => $this->filehash));
         return $upload->receive($this->field);
     } else {
         return false;
     }
 }
コード例 #19
0
ファイル: DbRestore.php プロジェクト: samlanh/lynacr
 public function UploadFileDatabase($data)
 {
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination(PUBLIC_PATH);
     $fileinfo = $adapter->getFileInfo();
     $rs = $adapter->receive();
     if ($rs == 1) {
         // 			return true;
         $file_name = $fileinfo['fileToUpload']['name'];
         $this->getRestoreDatabase($file_name);
     } else {
         return false;
     }
 }
コード例 #20
0
 protected function _imageResizeAndSave($object)
 {
     $path = APPLICATION_ROOT . '/public_html/images/eyecatchers/';
     $system->lng = $this->_getParam('lng');
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($path);
     $adapter->setOptions(array('ignoreNoFile' => true));
     if (!$adapter->receive()) {
         $msgr = Sanmax_MessageStack::getInstance('SxModule_Eyecatchers_Validator');
         $msgr->addMessage('file', $adapter->getMessages(), 'title');
     }
     if ($object->getPicture() == null) {
         $object->setPicture('');
     }
     $files = $adapter->getFileInfo();
     foreach ($files as $file) {
         if (!$file['tmp_name']) {
             continue;
         }
         $path0 = $path . "253x115/";
         $path1 = $path . "980x450/";
         if (!is_dir($path0)) {
             mkdir($path0, 0777, true);
         }
         if (!is_dir($path1)) {
             mkdir($path1, 0777, true);
         }
         $filename = $object->createThumbName($file['name']) . '_' . time() . '.png';
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(253, 115);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(100);
         $image->setBackgroundColor(new ImagickPixel('transparent'));
         $image->setImageFormat('png32');
         $image->writeImage($path0 . $filename);
         $image->clear();
         $image->destroy();
         $image = new Imagick($file['tmp_name']);
         $image->cropThumbnailImage(980, 450);
         $image->setCompression(Imagick::COMPRESSION_JPEG);
         $image->setImageCompressionQuality(75);
         $image->setBackgroundColor(new ImagickPixel('transparent'));
         $image->setImageFormat('png32');
         $image->writeImage($path1 . $filename);
         $image->clear();
         $image->destroy();
         unlink($file['tmp_name']);
         $object->setPicture($filename);
     }
 }
コード例 #21
0
 public function uploadAction()
 {
     if (!empty($_FILES)) {
         try {
             $path = '/var/apps/iphone/certificates/';
             $base_path = Core_Model_Directory::getBasePathTo($path);
             $filename = uniqid() . '.pem';
             $app_id = $this->getRequest()->getParam('app_id');
             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_Certificate();
             $certificat->find(array('type' => 'ios', 'app_id' => $app_id));
             if (!$certificat->getId()) {
                 $certificat->setType('ios')->setAppId($app_id);
             }
             $certificat->setPath($path . $filename)->save();
             $datas = array('success' => 1, 'files' => 'eeeee', 'message_success' => $this->_('Info 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));
     }
 }
コード例 #22
0
 public function introasyncajaxAction()
 {
     $this->getResponse()->setHeader('Content-Type', 'application/json');
     $this->_helper->viewRenderer->setNoRender(true);
     $this->_helper->layout()->disableLayout();
     $params = $this->_getAllParams();
     $intro = new Application_Model_O_GlobalConsultation();
     $validate = new Yy_Validate_Value();
     if ($validate->isValid($params['id'])) {
         $intro->setId($params['id']);
     } else {
         $intro->setCtime(date('Y-m-d H:i:s'));
     }
     if ($validate->isValid($params['title'])) {
         $intro->setTitle($params['title']);
     }
     if ($validate->isValid($params['content'])) {
         $intro->setContent($params['content']);
     }
     if ($validate->isValid($params['sort'])) {
         $intro->setSort($params['sort']);
     }
     if ($validate->isValid($params['status'])) {
         $intro->setStatus($params['status']);
     }
     try {
         $intro->save();
         $id = $intro->getId();
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $wrdir = Yy_Utils::getWriteDir();
         $adapter->setDestination($wrdir);
         if (!$adapter->receive()) {
             $messages = $adapter->getMessages();
             //echo implode("\n", $messages);
         }
         $filename = $adapter->getFileName();
         if (is_string($filename)) {
             $handle = fopen($filename, 'rb');
             $img = addslashes(fread($handle, filesize($filename)));
             fclose($handle);
             Application_Model_M_GlobalConsultation::updateImage($id, $img);
         }
         $url = '/diagnosis/introview?id=' . $id;
         $this->redirect($url);
     } catch (Zend_Db_Exception $e) {
         //$this->redirect('/error');
         $this->redirect('/error?message=' . $e->getMessage());
     }
 }
コード例 #23
0
ファイル: Foto.php プロジェクト: jager/cms
 private function transfer($destination)
 {
     //s( $destination ); return;
     if (!is_dir($destination)) {
         mkdir($destination, 0777, true);
     }
     $adapter = new Zend_File_Transfer_Adapter_Http();
     $adapter->setDestination($destination);
     if (!$adapter->receive()) {
         $messages = $adapter->getMessages();
         return implode("<br />", $messages);
     } else {
         return $adapter;
     }
 }
コード例 #24
0
 /**
  * Provides an image browser feature for the rich text editor
  *
  * @return void
  */
 public function browseAction()
 {
     $params = Zend_Registry::get('params');
     // This is displayed inside the editor - so we need set a blank layout (no header/footer)
     $this->_helper->layout->setLayout('popup');
     $gallery = new Datasource_Cms_Gallery();
     $categoryID = $this->getRequest()->getParam('cid');
     $editorFuncNum = $this->getRequest()->getParam('CKEditorFuncNum');
     if ($this->getRequest()->isPost()) {
         // A new image has been sent - handle it
         $upload = new Zend_File_Transfer_Adapter_Http();
         $upload->setDestination($params->cms->imageUploadPath);
         $upload->addValidator('Extension', false, 'jpg,jpeg,png,gif');
         $upload->addValidator('Count', false, 1);
         $upload->addValidator('Size', false, 10240000);
         if ($upload->receive()) {
             // File has been uploaded succesfully
             $this->view->uploadSuccess = true;
             $imageFilename = $upload->getFileName(null, false);
             $imageLocation = $upload->getFileName();
             list($imageWidth, $imageHeight) = getimagesize($imageLocation);
             $imageID = $gallery->addNew(0, $imageFilename, $imageWidth, $imageHeight);
             // Resize and save a few pr
             $cmsImage = new Application_Cms_Image();
             if ($imageWidth > $imageHeight) {
                 $cmsImage->resamplePhoto($imageLocation, $params->cms->imageUploadPath . '/previews/200_' . $imageFilename, 200, null);
                 $cmsImage->resamplePhoto($imageLocation, $params->cms->imageUploadPath . '/previews/400_' . $imageFilename, 400, null);
             } else {
                 $cmsImage->resamplePhoto($imageLocation, $params->cms->imageUploadPath . '/previews/200_' . $imageFilename, null, 150);
                 $cmsImage->resamplePhoto($imageLocation, $params->cms->imageUploadPath . '/previews/400_' . $imageFilename, null, 400);
             }
             $this->_helper->getHelper('FlashMessenger')->addMessage(array('deleted' => true));
             // $this->_helper->getHelper('Redirector')->goToUrl('/cms-admin/images/edit?id='. $imageID); // Forward to image editor
             $this->_helper->getHelper('Redirector')->goToUrl('/cms-admin/images/browse?CKEditorFuncNum=' . $editorFuncNum);
         } else {
             // An error occurred - deal with the error messages
             $errorMessages = $upload->getMessages();
         }
     } else {
         // No image uploaded - show the gallery
         if (!$categoryID) {
             $categoryID = 0;
         }
         $imageList = $gallery->getImagesByCategoryID($categoryID);
         $this->view->imageList = $this->view->partialLoop('partials/image-browser-image.phtml', $imageList);
         $this->view->editorFuncNum = $editorFuncNum;
     }
 }
コード例 #25
0
ファイル: CityController.php プロジェクト: riteshsahu1981/we
 public function addAction()
 {
     $userNs = new Zend_Session_Namespace("members");
     $this->view->title = "City - Add";
     $this->view->headTitle(" -  " . $this->view->title);
     $form = new Admin_Form_City();
     $this->view->form = $form;
     $this->view->successMsg = "";
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $upload = new Zend_File_Transfer_Adapter_Http();
             //---main image
             if ($upload->isValid('logo')) {
                 $upload->setDestination("images/logo/");
                 try {
                     $upload->receive('logo');
                 } catch (Zend_File_Transfer_Exception $e) {
                     $msg = $e->getMessage();
                 }
                 $upload->setOptions(array('useByteString' => false));
                 $id = time();
                 $file_name = $upload->getFileName('logo');
                 $cardImageTypeArr = explode(".", $file_name);
                 $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]);
                 $target_file_name = "logo_" . $id . ".{$ext}";
                 $targetPath = 'media/picture/city/logo/' . $target_file_name;
                 $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true));
                 $filterFileRename->filter($file_name);
                 $formData['logo'] = $target_file_name;
                 /*--- Generate Thumbnail ---*/
                 $thumb = Base_Image_PhpThumbFactory::create($targetPath);
                 $thumb->resize(100, 100);
                 $thumb->save($targetPath = 'media/picture/city/logo/thumb_' . $target_file_name);
             }
             $usersNs = new Zend_Session_Namespace("members");
             $formData['userId'] = $usersNs->userId;
             $this->view->warningMsg = '';
             $model = new Application_Model_City($formData);
             $id = $model->save($model);
             $form->reset();
             $this->view->successMsg = "City added successfully. City Id : {$id}";
         } else {
             $form->populate($formData);
         }
     }
 }
コード例 #26
0
ファイル: UploadController.php プロジェクト: rickyfeng/wenda
 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;
     }
 }
コード例 #27
0
ファイル: DbStuff.php プロジェクト: samlanh/lynacr
 function updateStuff($_data)
 {
     $db = $this->getAdapter();
     $db->beginTransaction();
     try {
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $part = PUBLIC_PATH . '/images';
         $adapter->setDestination($part);
         $adapter->receive();
         $photo = $adapter->getFileInfo();
         if (!empty($photo['front_Veiw']['name'])) {
             $_data['front_Veiw'] = $photo['front_Veiw']['name'];
         } else {
             $_data['front_Veiw'] = $_data['old_front_Veiw'];
         }
         if (!empty($photo['Front_Right']['name'])) {
             $_data['Front_Right'] = $photo['Front_Right']['name'];
         } else {
             $_data['Front_Right'] = $_data['old_Front_Right'];
         }
         if (!empty($photo['front_left']['name'])) {
             $_data['front_left'] = $photo['front_left']['name'];
         } else {
             $_data['front_left'] = $_data['old_Front_Right'];
         }
         if (!empty($photo['rear_left']['name'])) {
             $_data['rear_left'] = $photo['rear_left']['name'];
         } else {
             $_data['rear_left'] = $_data['old_Front_Right'];
         }
         $_arr = array('equipment_name' => $_data['Eq_name'], 'reference_no' => $_data['Referent'], 'url' => $_data['Url'], 'status' => $_data['status'], 'photo_front' => $_data['front_Veiw'], 'photo_front_right' => $_data['Front_Right'], 'photo_front_left' => $_data['front_left'], 'photo_rear_left' => $_data['rear_left'], 'year' => $_data['year'], 'color' => $_data['color'], 'model' => $_data['model'], 'size' => $_data['size'], 'serial_no' => $_data['serial_no'], 'other' => $_data['other'], 'telephone_num' => $_data['telephone_num'], 'cell_phone' => $_data['cell_phone'], 'type' => $_data['type'], 'sim_card' => $_data['sim_card'], 'user_id' => $this->getUserId());
         $where = "id=" . $_data['id'];
         $id = $this->update($_arr, $where);
         $this->_name = 'ldc_stuff_details';
         $where = " stuff_id = " . $_data['id'];
         $this->delete($where);
         $ids = explode(',', $_data['record_row']);
         foreach ($ids as $i) {
             $item = array('stuff_id' => $_data['id'], 'package_id' => $_data['package_id' . $i], 'price' => $_data['price_' . $i], 'extra_price' => $_data['extracharge_' . $i], 'note' => $_data['note_' . $i], 'date' => date("Y-m-d"), 'user_id' => $this->getUserId());
             $this->insert($item);
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         echo $e->getMessage();
     }
 }
コード例 #28
0
ファイル: FilesController.php プロジェクト: besters/My-Base
 public function indexAction()
 {
     $s3 = new Zend_Service_Amazon_S3('AKIAJ5HTOSBB7ITPA6VQ', 'n8ZjV8xz/k/FxBGhrVduYlSXVFFmep7aZJ/NOsoj');
     $this->view->buckets = $s3->getBuckets();
     $bucketName = 'vaultman';
     $ret = $s3->getObjectsByBucket($bucketName);
     $this->view->objects = $ret;
     $this->view->form = new Mybase_Form_Files();
     $formData = $this->getRequest()->getPost();
     if ($this->_request->isPost()) {
         $s3->registerStreamWrapper("s3");
         //file_put_contents("s3://".$bucketName."/".$_FILES['img']['name'], fopen($_FILES['img']['tmp_name'], 'r'));
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $adapter->setDestination("s3://" . $bucketName . "/");
         //$adapter->receive();
     }
 }
コード例 #29
0
ファイル: SheetController.php プロジェクト: hollusion/Netons
 public function uploadAction()
 {
     $request = $this->getRequest();
     $table = new Model_DbTable_Sheets();
     $select = $table->select();
     $select->where('id = ?', $request->id);
     $sheet = $table->fetchRow($select);
     if (!$this->view->authenticated || $sheet->user_id != $this->view->identity->id) {
         $this->_redirector->gotoRoute(array(), 'login');
     }
     if ($request->isPost()) {
         $path = UPLOAD_PATH . '/sheets/';
         if (!file_exists($path)) {
             mkdir(str_replace('//', '/', $path), 0755, true);
         }
         $upload = new Zend_File_Transfer_Adapter_Http();
         $upload->setDestination($path);
         $upload->addValidators(array(array('Count', false, 5), array('Size', false, '2MB'), array('Extension', false, array('pdf', 'midi', 'mid'))));
         if ($upload->isValid()) {
             $table = new Model_DbTable_Downloads();
             $pattern = array('/-/', '/_/', '/\\s+/');
             $replace = array(' - ', ' ', ' ');
             foreach ($upload->getFileInfo() as $file => $contents) {
                 $info = pathinfo($contents['name']);
                 $row = $table->createRow();
                 $row->sheet_id = $sheet->id;
                 $row->type = strtolower($info['extension']) == 'pdf' ? 'PDF' : 'MIDI';
                 $title = preg_replace($pattern, $replace, $info['filename']);
                 $row->title = ucwords($title);
                 $row->save();
                 $name = $row->id . ($row->type == 'MIDI' ? '.mid' : '.pdf');
                 $upload->addFilter('Rename', array('target' => $name), $file);
                 $upload->receive($file);
             }
             if ($upload->isReceived()) {
                 return $this->_redirector->gotoRoute(array('controller' => 'sheet', 'id' => $request->id), 'view');
             }
         }
         $this->view->errors = $upload->getMessages();
     }
     $this->view->headTitle('Upload sheet file(s)');
     $this->view->headScript()->appendFile('/js/multifile.js');
     $this->view->headScript()->appendFile('/js/upload.js');
     $this->view->sheetId = $request->id;
 }
コード例 #30
-1
ファイル: Imagem.php プロジェクト: sgdoc/sgdoce-codigo
 /**
  * Metdo responsavel por persistir os uploads
  * @param type $destino
  * @param type $thumb
  * @param type $validFile
  * @param type $invalidFile
  * @return type
  */
 public static function upload($destino = 'anexoArtefato', $thumb = FALSE, $validFile = TRUE, $invalidFile = TRUE, $validImageSize = TRUE)
 {
     $configs = \Core_Registry::get('configs');
     $upload = new \Zend_File_Transfer_Adapter_Http();
     $files = $upload->getFileInfo();
     $filesUp = array();
     $return = array();
     $error = false;
     $pasta = 'anexo-material';
     if ($destino == 'anexoArtefato') {
         $pasta = 'anexo-artefato';
     }
     $path = current(explode('application', __DIR__)) . 'data' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $pasta . DIRECTORY_SEPARATOR;
     foreach ($files as $file => $info) {
         $upload = new \Zend_File_Transfer_Adapter_Http();
         $upload->setDestination($path);
         $upload->setValidators(array());
         $upload->addValidator('Size', TRUE, array('max' => '100MB', 'messages' => "O tamanho do arquivo é superior ao permitido. O tamanho permitido é 100MB."));
         self::_invalidFile($invalidFile, $upload);
         self::_validFile($validFile, $upload);
         self::_validImageSize($validImageSize, $upload);
         self::_getValidator($upload);
         if ($upload->isValid($file)) {
             $fileinfo = pathinfo($info['name']);
             $upload->receive($file);
             $filesUp[] = $upload->getFileName($file);
             $return[] = array('name' => $upload->getFileName($file), 'size' => $upload->getFileSize($file));
         } else {
             $error = $upload->getMessages();
             break;
         }
     }
     if ($error) {
         if (count($filesUp)) {
             foreach ($filesUp as $file) {
                 unlink($file);
             }
         }
         return array('errors' => $error);
     }
     if ($thumb) {
         $pasta = current(explode('application', __DIR__)) . 'data' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR;
         foreach ($filesUp as $endereco) {
             $fileinfo = pathinfo($endereco);
             $image = \WideImage::load($endereco);
             $image->resize(300, 300, 'outside')->crop('50% - 150', '50% - 150', 300, 300)->saveToFile($pasta . $fileinfo['filename'] . '_300_X_300.' . strtolower($fileinfo['extension']));
             $image->resize(133, 89, 'outside')->crop('50% - 67', '50% - 45', 133, 89)->saveToFile($pasta . $fileinfo['filename'] . '_133_X_89.' . strtolower($fileinfo['extension']));
         }
     }
     return $return;
 }