/** * Use the Zend_File_Transfer adapter to upload the file. * * @internal The resulting filename is retrieved via the adapter's * getFileName() method. * * @param array $fileInfo * @param string $originalFilename * @return string Path to the file in Omeka. */ protected function _transferFile($fileInfo, $originalFilename) { // Upload a single file at a time. if (!$this->_adapter->receive($fileInfo['form_index'])) { throw new Omeka_File_Ingest_InvalidException(join("\n\n", $this->_adapter->getMessages())); } // Return the path to the file as it is listed in Omeka. return $this->_adapter->getFileName($fileInfo['form_index']); }
public function signupAction() { $users = new Application_Model_User(); $form = new Application_Form_Registration(); $this->view->form = $form; // Define a transport and set the destination on the server // $upload = new Zend_File_Transfer_Adapter_Http(); // $upload->addFilter('Rename', APPLICATION_PATH . '/../data/'.'jpg'); // $upload->addFilter('Rename', APPLICATION_PATH . '/../data/'); // Zend_Debug::dump($upload->getFileInfo()); if ($this->getRequest()->isPost()) { if ($form->isValid($_POST)) { // $upload->setDestination('data/'); // // $upload->receive(); $data = $form->getValues(); $upload = new Zend_File_Transfer_Adapter_Http(); $upload->receive(); if ($data['password'] != $data['confirmPassword']) { $this->view->errorMessage = "Password and confirm password don't match."; return; } if ($users->checkUnique($data['name'])) { $this->view->errorMessage = "Name already taken. Please choose another one."; return; } unset($data['confirmPassword']); $users->insert($data); echo 'tmaaaaaaaam'; $this->_redirect('auth/login'); echo 'tmaaaaaaaam'; } } }
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"); } }
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); }
/** * 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; }
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"); }
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'); } }
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); } }
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); }
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'); } }
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'); } } }
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()); } } }
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 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'); }
/** * upload */ public function uploadAction() { // disable layouts for this action: $this->_helper->layout->disableLayout(); if ($this->_request->isPost()) { try { $destination = PUBLIC_PATH . "/uploads/files"; /* Check destination folder */ if (!is_dir($destination)) { if (is_writable(PUBLIC_PATH . "/uploads")) { mkdir($destination); } else { throw new Exception("Uploads directory is not writable"); } } /* Uploading Document File on Server */ $upload = new Zend_File_Transfer_Adapter_Http(); try { // upload received file(s) $upload->receive(); } catch (Zend_File_Transfer_Exception $e) { $e->getMessage(); } // you MUST use following functions for knowing about uploaded file // Returns the file name for 'doc_path' named file element $filePath = $upload->getFileName('file'); // pathinfo $name = pathinfo($filePath, PATHINFO_FILENAME); $ext = pathinfo($filePath, PATHINFO_EXTENSION); // prepare filename $name = strtolower($name); $name = preg_replace('/[^a-z0-9_-]/', '-', $name); // prepare extension if ($ext == 'php' or $ext == 'php4' or $ext == 'php5' or $ext == 'phtml') { $ext = 'phps'; } // rename uploaded file $renameFile = $name . '.' . $ext; $counter = 0; while (file_exists($destination . '/' . $renameFile)) { $counter++; $renameFile = $name . '-' . $counter . '.' . $ext; } $fileIco = $this->getIco($ext); $fullFilePath = $destination . '/' . $renameFile; // Rename uploaded file using Zend Framework $filterFileRename = new Zend_Filter_File_Rename(array('target' => $fullFilePath, 'overwrite' => true)); $filterFileRename->filter($filePath); $this->_helper->viewRenderer->setNoRender(true); $link = '<a href="javascript:void(null);" rel="' . $renameFile . '" class="redactor_file_link redactor_file_ico_' . $fileIco . '" title="' . $renameFile . '">' . $renameFile . '</a>'; echo $link; } catch (Exception $e) { $this->_forwardError($e->getMessage()); } } else { $this->_forwardError('Internal Error of Uploads controller'); } }
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; }
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; } }
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; } }
/** * 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); }
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(); }
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); } }
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); } }
/** * 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; } }
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; } }
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()); } }
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; } }
/** * 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; } }
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)); } }
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(); } }
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; } }