public function createAction() { parent::postDispatch(); $auth = Zend_Auth::getInstance(); if (!$auth->hasIdentity()) { $this->redirect('/auth'); } $dbTable = new Application_Model_DbTable_Block(); $adapter = new Zend_File_Transfer_Adapter_Http(); $options = array('ignoreNoFile' => true); $adapter->setOptions($options); $info = $adapter->getFileInfo(); // Redireciona para home depois do submit if (isset($_POST['submit'])) { //Envia para a tabela um novo bloco criada. $adapter->setDestination('c:/teste'); $link_file = $adapter->getFileName(); $name_file = $adapter->getFileName(null, false); $text = $_POST['text']; $author = $_POST['author']; $type = $_POST['type']; $dbTable->insert(array('date' => date('Y-m-d H:i:s'), 'text' => "{$text}", 'type' => "{$type}")); $adapter->receive(); header('Location: ../'); } }
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"); } }
/** * Bulk product upload functinality for seller * * @return void */ public function bulkuploadAction() { /** * Check license key */ Mage::helper('marketplace')->checkMarketplaceKey(); /** * Check whether seller or not */ $this->checkWhetherSellerOrNot(); try { /** * New zend File Uploader */ $uploadsData = new Zend_File_Transfer_Adapter_Http(); $filesDataArray = $uploadsData->getFileInfo(); /** * Checking whether csv exist or not */ if (!empty($filesDataArray)) { $this->saveBulkUploadFiles($filesDataArray); } } catch (Exception $e) { /** * Display error message for csv file upload */ Mage::getSingleton('core/session')->addError($this->__($e->getMessage())); $this->_redirect('marketplace/product/manage'); return; } }
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 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); }
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 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 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 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 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 saveProviderAction($providerId, Form_GenericProviderConfiguration $form, $action, $actionType) { $actionObject = null; $contentDistributionPlugin = Kaltura_Client_ContentDistribution_Plugin::get($this->client); try { $actionObject = $contentDistributionPlugin->genericDistributionProviderAction->getByProviderId($providerId, $actionType); } catch (Exception $e) { } $isNew = true; if ($actionObject) { $isNew = false; } else { $actionObject = new Kaltura_Client_ContentDistribution_Type_GenericDistributionProviderAction(); $actionObject->genericDistributionProviderId = $providerId; $actionObject->action = $actionType; } $actionObject = $form->getActionObject($actionObject, $action, $actionType); if (!$actionObject) { if (!$isNew) { $contentDistributionPlugin->genericDistributionProviderAction->deleteByProviderId($providerId, $actionType); } return; } $genericDistributionProviderAction = null; if ($isNew) { $genericDistributionProviderAction = $contentDistributionPlugin->genericDistributionProviderAction->add($actionObject); } else { // reset all readonly fields $actionObject->id = null; $actionObject->createdAt = null; $actionObject->updatedAt = null; $actionObject->genericDistributionProviderId = null; $actionObject->action = null; $actionObject->status = null; $actionObject->mrssTransformer = null; $actionObject->mrssValidator = null; $actionObject->resultsTransformer = null; $genericDistributionProviderAction = $contentDistributionPlugin->genericDistributionProviderAction->updateByProviderId($providerId, $actionType, $actionObject); } $genericDistributionProviderActionId = $genericDistributionProviderAction->id; $upload = new Zend_File_Transfer_Adapter_Http(); $files = $upload->getFileInfo(); if (count($files)) { if (isset($files["mrssTransformer{$action}"]) && $files["mrssTransformer{$action}"]['size']) { $file = $files["mrssTransformer{$action}"]; $contentDistributionPlugin->genericDistributionProviderAction->addMrssTransformFromFile($genericDistributionProviderActionId, $file['tmp_name']); } if (isset($files["mrssValidator{$action}"]) && $files["mrssValidator{$action}"]['size']) { $file = $files["mrssValidator{$action}"]; $contentDistributionPlugin->genericDistributionProviderAction->addMrssValidateFromFile($genericDistributionProviderActionId, $file['tmp_name']); } if (isset($files["resultsTransformer{$action}"]) && $files["resultsTransformer{$action}"]['size']) { $file = $files["resultsTransformer{$action}"]; $contentDistributionPlugin->genericDistributionProviderAction->addResultsTransformFromFile($genericDistributionProviderActionId, $file['tmp_name']); } } }
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 getObject($objectType, array $properties, $add_underscore = true, $include_empty_fields = false) { $object = parent::getObject($objectType, $properties, $add_underscore, $include_empty_fields); $upload = new Zend_File_Transfer_Adapter_Http(); $files = $upload->getFileInfo(); if (count($files) && isset($files["xslfile"]) && $files["xslfile"]['size']) { $object->xsl = file_get_contents($files["xslfile"]['tmp_name']); } return $object; }
public function getObject($objectType, array $properties, $add_underscore = true, $include_empty_fields = false) { /* @var $object Kaltura_Client_FtpDistribution_Type_FtpDistributionProfile */ $object = parent::getObject($objectType, $properties, $add_underscore, true); $upload = new Zend_File_Transfer_Adapter_Http(); $files = $upload->getFileInfo(); if (isset($files['sftp_public_key'])) { $object->sftpPublicKey = $this->getFileContent($files['sftp_public_key']); } if (isset($files['sftp_private_key'])) { $object->sftpPrivateKey = $this->getFileContent($files['sftp_private_key']); } if (isset($files['aspera_public_key'])) { $object->asperaPublicKey = $this->getFileContent($files['aspera_public_key']); } if (isset($files['aspera_private_key'])) { $object->asperaPrivateKey = $this->getFileContent($files['aspera_private_key']); } $updateRequiredEntryFields = array(); $updateRequiredMetadataXpaths = array(); $entryFields = array_keys($this->getEntryFields()); $metadataXpaths = array_keys($this->getMetadataFields()); $fieldConfigArray = $object->fieldConfigArray; foreach ($properties as $property => $value) { if (!$value) { continue; } $updateField = null; $matches = null; if (preg_match('/update_required_entry_fields_(\\d+)$/', $property, $matches)) { $index = $matches[1]; if (isset($entryFields[$index])) { $updateField = $entryFields[$index]; } } if (preg_match('/update_required_metadata_xpaths_(\\d+)$/', $property, $matches)) { $index = $matches[1]; if (isset($metadataXpaths[$index])) { $updateField = $metadataXpaths[$index]; } } if ($updateField) { $fieldConfig = new Kaltura_Client_ContentDistribution_Type_DistributionFieldConfig(); $fieldConfig->fieldName = md5($updateField); // needs to have a value for the field to get saved $fieldConfig->updateOnChange = true; $string = new Kaltura_Client_Type_String(); $string->value = $updateField; $fieldConfig->updateParams = array($string); $fieldConfigArray[] = $fieldConfig; } } $object->fieldConfigArray = $fieldConfigArray; return $object; }
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; } }
public function __construct($arrParam = array(), $options = null) { ////////////////////////////////// //Kiem tra Name ///////////// ////////////////////////////////// if ($arrParam['action'] == 'add') { $options = array('table' => 'da_album', 'field' => 'album_name'); } elseif ($arrParam['action'] == 'edit') { $options = array('table' => 'da_album', 'field' => 'album_name', 'exclude' => array('field' => 'id', 'value' => $arrParam['id'])); } $validator = new Zend_Validate(); $validator->addValidator(new Zend_Validate_NotEmpty(), true)->addValidator(new Zend_Validate_StringLength(3, 100), true); if (!$validator->isValid($arrParam['album_name'])) { $message = $validator->getMessages(); $this->_messageError['album_name'] = 'Tên album: ' . current($message); $arrParam['album_name'] = ''; } ////////////////////////////////// //Kiem tra Picture small /////////// ////////////////////////////////// $upload = new Zend_File_Transfer_Adapter_Http(); $fileInfo = $upload->getFileInfo('picture'); $fileName = $fileInfo['picture']['name']; if (!empty($fileName)) { $upload->addValidator('Extension', true, array('jpg', 'gif', 'png'), 'picture'); $upload->addValidator('Size', true, array('min' => '2KB', 'max' => '1000KB'), 'picture'); if (!$upload->isValid('picture')) { $message = $upload->getMessages(); $this->_messageError['picture'] = 'Hình ảnh đại diện: ' . current($message); } } ////////////////////////////////// //Kiem tra Order ///////////// ////////////////////////////////// $validator = new Zend_Validate(); $validator->addValidator(new Zend_Validate_StringLength(1, 10), true)->addValidator(new Zend_Validate_Digits(), true); if (!$validator->isValid($arrParam['order'])) { $message = $validator->getMessages(); $this->_messageError['order'] = 'Sắp xếp: ' . current($message); $arrParam['order'] = ''; } ////////////////////////////////// //Kiem tra Status ///////////// ////////////////////////////////// if (empty($arrParam['status']) || !isset($arrParam['status'])) { $arrParam['status'] = 0; } //======================================== // TRUYEN CAC GIA TRI DUNG VAO MANG $_arrData //======================================== $this->_arrData = $arrParam; }
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(); }
public function actionInstall() { $this->_assertPostOnly(); $fileTransfer = new Zend_File_Transfer_Adapter_Http(); if ($fileTransfer->isUploaded('upload_file')) { $fileInfo = $fileTransfer->getFileInfo('upload_file'); $fileName = $fileInfo['upload_file']['tmp_name']; } else { $fileName = $this->_input->filterSingle('server_file', XenForo_Input::STRING); } $this->getModelFromCache('EWRporta_Model_Layouts')->installLayoutXmlFromFile($fileName); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('ewrporta/layouts')); }
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); } }
public function actionXenGallerySave() { $this->_assertPostOnly(); $input = $this->_input->filter(array('group_id' => XenForo_Input::STRING, 'options' => XenForo_Input::ARRAY_SIMPLE, 'options_listed' => array(XenForo_Input::STRING, array('array' => true)))); $options = XenForo_Application::getOptions(); $optionModel = $this->_getOptionModel(); $group = $optionModel->getOptionGroupById($input['group_id']); foreach ($input['options_listed'] as $optionName) { if ($optionName == 'xengalleryUploadWatermark') { continue; } if (!isset($input['options'][$optionName])) { $input['options'][$optionName] = ''; } } $delete = $this->_input->filterSingle('delete_watermark', XenForo_Input::BOOLEAN); if ($delete) { $existingWatermark = $options->get('xengalleryUploadWatermark'); if ($existingWatermark) { $watermarkWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Watermark', XenForo_DataWriter::ERROR_SILENT); $watermarkWriter->setExistingData($existingWatermark); $watermarkWriter->delete(); $input['options']['xengalleryUploadWatermark'] = 0; $optionModel->updateOptions($input['options']); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(XenForo_Link::buildAdminLink('options/list', $group))); } } $fileTransfer = new Zend_File_Transfer_Adapter_Http(); if ($fileTransfer->isUploaded('watermark')) { $fileInfo = $fileTransfer->getFileInfo('watermark'); $fileName = $fileInfo['watermark']['tmp_name']; $watermarkWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Watermark', XenForo_DataWriter::ERROR_SILENT); $existingWatermark = $options->get('xengalleryUploadWatermark'); if ($existingWatermark) { $watermarkWriter->setExistingData($existingWatermark); } $watermarkData = array('watermark_user_id' => XenForo_Visitor::getUserId(), 'is_site' => 1); $watermarkWriter->bulkSet($watermarkData); $watermarkWriter->save(); $image = new XenGallery_Helper_Image($fileName); $image->resize($options->xengalleryWatermarkDimensions['width'], $options->xengalleryWatermarkDimensions['height'], 'fit'); $watermarkModel = $this->_getWatermarkModel(); $watermarkPath = $watermarkModel->getWatermarkFilePath($watermarkWriter->get('watermark_id')); if (XenForo_Helper_File::createDirectory(dirname($watermarkPath), true)) { XenForo_Helper_File::safeRename($fileName, $watermarkPath); $input['options']['xengalleryUploadWatermark'] = $watermarkWriter->get('watermark_id'); } } $optionModel->updateOptions($input['options']); return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(XenForo_Link::buildAdminLink('options/list', $group))); }
public function getObject($objectType, array $properties, $add_underscore = true, $include_empty_fields = false) { $object = parent::getObject($objectType, $properties, $add_underscore, $include_empty_fields); if ($object instanceof Kaltura_Client_TvinciDistribution_Type_TvinciDistributionProfile) { $upload = new Zend_File_Transfer_Adapter_Http(); $files = $upload->getFileInfo(); if (isset($files['xsltFile'])) { $file = $files['xsltFile']; $content = file_get_contents($file['tmp_name']); $object->xsltFile = $content; } } return $object; }
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); } }
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 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)); } }
public function actionImport() { if (!$this->perms['admin']) { return $this->responseNoPermission(); } if (XenForo_Application::autoload('EWRmedio_XML_Premium')) { $fileTransfer = new Zend_File_Transfer_Adapter_Http(); if ($fileTransfer->isUploaded('upload_file')) { $fileInfo = $fileTransfer->getFileInfo('upload_file'); $fileName = $fileInfo['upload_file']['tmp_name']; $this->getModelFromCache('EWRmedio_Model_Services')->importService($fileName); } } return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('media/admin/services')); }
/** * Use the adapter to extract the array of file information. * * @param string|null $fileInfo The name of the form input to ingest. * @return array */ protected function _parseFileInfo($fileInfo) { if (!$this->_adapter) { $this->_buildAdapter(); } // Grab the info from $_FILES array (prior to receiving the files). $fileInfoArray = $this->_adapter->getFileInfo($fileInfo); // Include the index of the form so that we can use that if necessary. foreach ($fileInfoArray as $index => $info) { // We need the index of this as well b/c the file info is passed // around (not the form index). $info['form_index'] = $index; $fileInfoArray[$index] = $info; } return $fileInfoArray; }
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; } }
protected function _getMimeType() { if (extension_loaded('fileinfo')) { return $this->_uploadHandler->getMimeType(); } $files = $this->_uploadHandler->getFileInfo(); if (empty($files)) { return false; } $file = reset($files); unset($files); if (function_exists('getimagesize')) { $info = getimagesize($file['tmp_name']); return $info !== false ? $info['mime'] : false; } return false; }
/** * 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; }