本文整理汇总了PHP中Zend_File_Transfer_Adapter_Http::setOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_File_Transfer_Adapter_Http::setOptions方法的具体用法?PHP Zend_File_Transfer_Adapter_Http::setOptions怎么用?PHP Zend_File_Transfer_Adapter_Http::setOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_File_Transfer_Adapter_Http
的用法示例。
在下文中一共展示了Zend_File_Transfer_Adapter_Http::setOptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleFileTransfer
/**
* handleFileTransfer
* @author Thomas Schedler <tsh@massiveart.com>
*/
private function handleFileTransfer()
{
$this->objUpload = new Zend_File_Transfer_Adapter_Http();
$this->objUpload->setOptions(array('useByteString' => false));
/**
* validators for upload of media
*/
$arrExcludedExtensions = $this->core->sysConfig->upload->excluded_extensions->extension->toArray();
$this->objUpload->addValidator('Size', false, array('min' => 1, 'max' => $this->core->sysConfig->upload->max_filesize));
$this->objUpload->addValidator('ExcludeExtension', false, $arrExcludedExtensions);
/**
* check if medium is uploaded
*/
if (!$this->objUpload->isUploaded(self::UPLOAD_FIELD)) {
$this->core->logger->warn('isUploaded: ' . implode('\\n', $this->objUpload->getMessages()));
throw new Exception('File is not uploaded!');
}
/**
* check if upload is valid
*/
if (!$this->objUpload->isValid(self::UPLOAD_FIELD)) {
$this->core->logger->warn('isValid: ' . implode('\\n', $this->objUpload->getMessages()));
throw new Exception('Uploaded file is not valid!');
}
}
示例2: uploadFile
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);
}
}
示例3: addAction
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');
}
示例4: _imageResizeAndSave
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);
}
}
示例5: _imageResizeAndSave
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);
}
}
示例6: addAction
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);
}
}
}
示例7: uploadAttendanceSheet
public function uploadAttendanceSheet()
{
$targetPath = false;
$upload = new Zend_File_Transfer_Adapter_Http();
if ($upload->isValid('attendanceSheet')) {
$upload->setDestination("media/attendance/");
try {
$upload->receive('attendanceSheet');
} catch (Zend_File_Transfer_Exception $e) {
$msg = $e->getMessage();
}
$upload->setOptions(array('useByteString' => false));
$file_name = $upload->getFileName('attendanceSheet');
$cardImageTypeArr = explode(".", $file_name);
$ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]);
$target_file_name = "attendance_" . date("Y_m_d_H_i_s") . ".{$ext}";
$targetPath = 'media/attendance/' . $target_file_name;
$filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true));
$filterFileRename->filter($file_name);
}
return $targetPath;
}
示例8: resizeAndSave
public function resizeAndSave()
{
$path = APPLICATION_ROOT . '/public_html/images/doctors/';
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($path);
$adapter->setOptions(array('ignoreNoFile' => true));
if (!$adapter->receive()) {
$msgr = Sanmax_MessageStack::getInstance('SxModule_Doctor');
$msgr->addMessage('file', $adapter->getMessages(), 'file');
}
$files = $adapter->getFileInfo();
foreach ($files as $file) {
if ($file['tmp_name'] == '') {
continue;
}
$filename = $this->_doc->createThumbName($file['name']) . '_' . time() . '.png';
$path0 = $path . "100x100/";
$path1 = $path . "230x230/color/";
$path2 = $path . "230x230/fade/";
$path3 = $path . "110x110/color/";
$path4 = $path . "110x110/fade/";
if (!is_dir($path0)) {
mkdir($path0, 0777, true);
}
if (!is_dir($path1)) {
mkdir($path1, 0777, true);
}
if (!is_dir($path2)) {
mkdir($path2, 0777, true);
}
if (!is_dir($path3)) {
mkdir($path3, 0777, true);
}
if (!is_dir($path4)) {
mkdir($path4, 0777, true);
}
$image = new Imagick($file['tmp_name']);
$image->cropThumbnailImage(100, 100);
$image->setCompression(Imagick::COMPRESSION_JPEG);
$image->setImageCompressionQuality(100);
$image->setBackgroundColor(new ImagickPixel('transparent'));
$image->setImageFormat('png32');
$image->writeImage($path0 . $filename);
$image->clear();
$image->destroy();
$image1 = new Imagick($file['tmp_name']);
$image1->cropThumbnailImage(230, 230);
$image1->setCompression(Imagick::COMPRESSION_JPEG);
$image1->setImageCompressionQuality(100);
$image1->setBackgroundColor(new ImagickPixel('transparent'));
$image1->setImageFormat('png32');
$image1->writeImage($path1 . $filename);
$image1->setimagetype(Imagick::IMGTYPE_GRAYSCALE);
$image1->writeImage($path2 . $filename);
$image1->clear();
$image1->destroy();
$image1 = new Imagick($file['tmp_name']);
$image1->cropThumbnailImage(110, 110);
$image1->setCompression(Imagick::COMPRESSION_JPEG);
$image1->setImageCompressionQuality(100);
$image1->setBackgroundColor(new ImagickPixel('transparent'));
$image1->setImageFormat('png32');
$image1->writeImage($path3 . $filename);
$image1->setimagetype(Imagick::IMGTYPE_GRAYSCALE);
$image1->writeImage($path4 . $filename);
$image1->clear();
$image1->destroy();
unlink($file['tmp_name']);
$this->_doc->setPhoto($filename);
}
}
示例9: uploadCoverImage
public function uploadCoverImage($id, $options)
{
$model = new Application_Model_Album();
$model = $model->find($id);
$upload = new Zend_File_Transfer_Adapter_Http();
if ($upload->isValid('coverImage')) {
$upload->setDestination("media/picture/album/");
try {
$upload->receive('coverImage');
} catch (Zend_File_Transfer_Exception $e) {
$msg = $e->getMessage();
}
$upload->setOptions(array('useByteString' => false));
$file_name = $upload->getFileName('coverImage');
$cardImageTypeArr = explode(".", $file_name);
$ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]);
$target_file_name = "album_cover_" . $id . ".{$ext}";
$targetPath = 'media/picture/album/' . $target_file_name;
$filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true));
$filterFileRename->filter($file_name);
$options['coverImage'] = $target_file_name;
/*--- Generate Profile Picture ---*/
$thumb = Base_Image_PhpThumbFactory::create($targetPath);
$thumb->resize(150, 150);
$thumb->save('media/picture/album/thumb_' . $target_file_name);
$model->setCoverImage($options['coverImage']);
return $model->save();
}
}
示例10: editAction
public function editAction()
{
$this->view->type = $type = $this->_getParam('type', "other");
$this->view->title = ucfirst($type) . " Category - Edit";
$this->view->headTitle(" - " . $this->view->title);
$id = $this->_getParam('id');
$model1 = new Application_Model_Category();
$model = $model1->find($id);
$options['name'] = $model->getName();
$options['urlText'] = $model->getUrlText();
$options['urlLink'] = $model->getUrlLink();
$options['description'] = $model->getDescription();
$options['image'] = $model->getImage();
$options['status'] = $model->getStatus();
$options['weight'] = $model->getWeight();
$this->view->imgName = $model->getImage();
$request = $this->getRequest();
$form = new Admin_Form_Category();
$form->populate($options);
//remove weight field for all type of categories except advice and wsv category
if ($type == "album" || $type == "blog" || $type == "work" || $type == "study" || $type == "volunteer" || $type == "other") {
$form->removeElement('weight');
}
//Url Link and Url Text fields should appear for WSV categories only
if ($type != "wsv") {
$form->removeElement('urlText');
$form->removeElement('urlLink');
}
$options = $request->getPost();
if ($request->isPost()) {
if ($form->isValid($options)) {
$category_id = $model->getId();
$upload = new Zend_File_Transfer_Adapter_Http();
//---main image
if ($upload->isValid('image')) {
$upload->setDestination("images/uploads/");
try {
$upload->receive('image');
} catch (Zend_File_Transfer_Exception $e) {
$msg = $e->getMessage();
}
$upload->setOptions(array('useByteString' => false));
//delete existing files
if ($model->getImage() != "" && file_exists("media/picture/category/" . $type . "/" . $model->getImage())) {
unlink("media/picture/category/" . $type . "/" . $model->getImage());
unlink("media/picture/category/" . $type . "/thumb_" . $model->getImage());
}
$id = $category_id;
$file_name = $upload->getFileName('image');
$cardImageTypeArr = explode(".", $file_name);
$ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]);
$target_file_name = "category_" . $id . ".{$ext}";
$targetPath = 'media/picture/category/' . $type . '/' . $target_file_name;
$filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true));
$filterFileRename->filter($file_name);
$options['image'] = $target_file_name;
/*--- Generate Thumbnail ---*/
$thumb = Base_Image_PhpThumbFactory::create($targetPath);
$thumb->resize(100, 100);
$thumb->save($targetPath = 'media/picture/category/' . $type . '/thumb_' . $target_file_name);
}
//-----------
$model->setOptions($options);
$model->save($model);
$model->updateRelatedSeoUrls($id);
$this->view->successMsg = "Category has been updated successfully!";
} else {
$form->reset();
$form->populate($options);
}
}
$this->view->form = $form;
}
示例11: addPrintAction
public function addPrintAction()
{
parent::postDispatch();
$auth = Zend_Auth::getInstance();
if (!$auth->hasIdentity()) {
$this->redirect('/auth');
}
$adapter = new Zend_File_Transfer_Adapter_Http();
$dbTable = new Application_Model_DbTable_Block();
$options = array('ignoreNoFile' => true);
$adapter->setOptions($options);
$lastText = $dbTable->getTextById($_GET['id']);
$this->view->block = $lastText;
if (isset($_POST['submit'])) {
// Enviar a atualização para o banco.
$adapter->setDestination('c:/teste');
$link_file = $adapter->getFileName();
$name_file = $adapter->getFileName(null, false);
$dbTable->update(array('date' => date('Y-m-d H:i:s'), 'name_pdf' => "{$name_file}", 'link_pdf' => "{$link_file}"), array('id = ? ' => $_GET['id']));
$adapter->receive();
header('Location: ../');
}
}
示例12: uploadPicture
public function uploadPicture($options)
{
$upload = new Zend_File_Transfer_Adapter_Http();
$albumId = $options['album_id'];
$targetFolder = PUBLIC_PATH . "/media/picture/album/{$albumId}";
if (!is_dir($targetFolder)) {
mkdir(str_replace('//', '/', $targetFolder), 0755, true);
}
if ($upload->isValid('Filedata')) {
$upload->setDestination($targetFolder);
try {
$upload->receive('Filedata');
} catch (Zend_File_Transfer_Exception $e) {
$msg = $e->getMessage();
}
$upload->setOptions(array('useByteString' => false));
$file_name = $upload->getFileName('Filedata');
$model = new Application_Model_Pictures();
$model->setAlbumId($albumId);
$model->setImage($file_name);
$id = $model->save();
$cardImageTypeArr = explode(".", $file_name);
$ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]);
$target_file_name = "album_picture_" . $id . ".{$ext}";
$targetPath = $targetFolder . '/' . $target_file_name;
$filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true));
$filterFileRename->filter($file_name);
/*--- Generate Profile Picture ---*/
$thumb = Base_Image_PhpThumbFactory::create($targetPath);
$thumb->resize(600, 600);
$thumb->save($targetFolder . '/small_' . $target_file_name);
$thumb = Base_Image_PhpThumbFactory::create($targetPath);
$thumb->resize(150, 150);
$thumb->save($targetFolder . '/thumb_' . $target_file_name);
$model = new Application_Model_Pictures();
$model = $model->find($id);
$model->setImage($target_file_name);
$model->save();
$str = "<div class='album_pic_thumb_box' id='pic_container_" . $model->getId() . "'>";
$str .= '<a class="album_pic_slide" href="' . $model->getPictureSmallUrl() . '"><img class="album_pic_thumb" src="' . $model->getPictureThumbUrl() . '"/></a>';
$str .= '<br class="clear">';
$str .= "<a href=\"javascript: deletePic('" . $model->getId() . "');\">";
$str .= "<img src=\"/images/icons/cross_circle.png\" alt=\"Click here to delete!\">";
$str .= "</a>";
$str .= "</div>";
return $str;
}
}
示例13: addAction
public function addAction()
{
$request = $this->getRequest();
$form = new Admin_Form_User();
$options = $request->getPost();
if ($request->isPost()) {
/*---- email validation ----*/
$form->getElement('email')->addValidators(array(array('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'email', 'messages' => 'Email already exists, Please choose another email address.'))));
/*-------------------------*/
if ($form->isValid($options)) {
$model = new Application_Model_User();
$options['dob'] = $options['year'] . "-" . $options['month'] . "-" . $options['day'];
$options['status'] = 'active';
$options['password'] = md5($options['password']);
$options['preferredLanguage'] = 'English';
//$options['userLevelId'] =$options['userLevelId'];
//$model->setOptions($options);
// $id=$model->save();
/*--------- Upload image START -------------------------*/
$upload = new Zend_File_Transfer_Adapter_Http();
if ($upload->isValid('image')) {
$upload->setDestination("media/picture/profile/");
try {
$upload->receive('image');
} catch (Zend_File_Transfer_Exception $e) {
$msg = $e->getMessage();
}
$upload->setOptions(array('useByteString' => false));
$file_name = $upload->getFileName('image');
$cardImageTypeArr = explode(".", $file_name);
$ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]);
$target_file_name = "profile_" . $id . ".{$ext}";
$targetPath = 'media/picture/profile/' . $target_file_name;
$filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true));
$filterFileRename->filter($file_name);
$options['image'] = $target_file_name;
/*--- Generate Thumbnail ---*/
$thumb = Base_Image_PhpThumbFactory::create($targetPath);
$thumb->resize(100, 100);
$thumb->save($targetPath = 'media/picture/profile/thumb_' . $target_file_name);
$model->setOptions($options);
$model->setId($id);
$id = $model->save();
}
/*--------- Upload image END -------------------------*/
//$options['dob'] = $options['year']."-".$options['month']."-".$options['day'];
//$model->setOptions($options);
//$model->save();
$user = new Application_Model_User($options);
$user_id = $user->save();
if ($user_id > 0) {
/*---- default permission settings ----*/
$user->setDefaultPermissions($user_id);
$user->setDefaultJournal($user_id);
}
$this->view->msg = "'User has been inserted successfully!";
$form->reset();
} else {
$form->reset();
$form->populate($options);
}
}
$this->view->form = $form;
}
示例14: editAction
public function editAction()
{
$id = $this->_getParam('id');
$preview = false;
$preview = $this->_getParam('preview');
//echo "diana==>".base64_encode(85);
$this->view->id = $id;
$this->view->preview = $preview;
$page = new Application_Model_Advice();
$page = $page->find($id);
$options = array('categoryId' => $page->getCategoryId(), 'title' => $page->getTitle(), 'identifire' => $page->getIdentifire(), 'name' => $page->getName(), 'content' => $page->getContent(), 'synopsis' => $page->getSynopsis(), 'metaTitle' => $page->getMetaTitle(), 'metaDescription' => $page->getMetaDescription(), 'metaKeyword' => $page->getMetaKeyword(), 'status' => $page->getStatus(), 'name' => $page->getName(), 'userId' => $page->getUserId());
$request = $this->getRequest();
$form = new Admin_Form_Advice();
//clear form element decorators
$elements = $form->getElements();
$form->clearDecorators();
foreach ($elements as $element) {
$element->removeDecorator('label');
$element->removeDecorator('td');
$element->removeDecorator('tr');
$element->removeDecorator('row');
$element->removeDecorator('HtmlTag');
$element->removeDecorator('class');
$element->removeDecorator('placement');
$element->removeDecorator('data');
}
//$this->view->type = $page->getType();
$this->view->imgName = $page->getName();
$form->populate($options);
if ($request->isPost()) {
$options = $request->getPost();
if (trim($options['identifire']) == "") {
$sanitize = new Base_Sanitize();
$options['identifire'] = $options['title'];
}
if (trim($options['identifire']) != "") {
$sanitize = new Base_Sanitize();
$options['identifire'] = $sanitize->clearInputs($options['identifire']);
$options['identifire'] = $sanitize->sanitize($options['identifire']);
//update seo url table
$seo_url_title = $options['identifire'];
$adviceM = new Application_Model_Advice();
$advice = $adviceM->find($id);
$seo_url = "";
$actual_url = "/advice/detail/id/{$id}";
if (false !== $advice) {
$sanitizeM = new Base_Sanitize();
//$category_id = $advice->getCategoryId();
$category_id = $options['categoryId'];
$categoryM = new Application_Model_Category();
$category = $categoryM->find($category_id);
if (false !== $category) {
$seo_url = "/advice/" . $sanitizeM->sanitize($category->getName()) . "/" . $seo_url_title;
}
}
$seoUrlM = new Application_Model_SeoUrl();
$soeUrl = $seoUrlM->fetchRow("actual_url='{$actual_url}'");
if (false !== $soeUrl) {
if ($seo_url != "") {
$soeUrl->setSeoUrl($seo_url);
$soeUrl->save();
}
} else {
if ($seo_url != "") {
$seoUrl = new Application_Model_SeoUrl();
$seoUrl->setActualUrl($actual_url);
$seoUrl->setSeoUrl($seo_url);
$seoUrl->save();
}
}
}
//save data
if ($form->isValid($options)) {
//set previous image name if not uploaded new one
$options['name'] = $page->getName();
/*------------------------------ Image Upload START ---------------------------*/
$upload = new Zend_File_Transfer_Adapter_Http();
if ($upload->isValid()) {
$upload->setDestination("images/advice/");
try {
$upload->receive();
} catch (Zend_File_Transfer_Exception $e) {
$msg = $e->getMessage();
}
//unlink previous uploaded image files
unlink("images/advice/" . $page->getName());
unlink("images/advice/thumb_" . $page->getName());
$upload->setOptions(array('useByteString' => false));
$file_name = $upload->getFileName('name');
$cardImageTypeArr = explode(".", $file_name);
$ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]);
$target_file_name = "advice_" . time() . ".{$ext}";
$targetPath = 'images/advice/' . $target_file_name;
$targetPathThumb = 'images/advice/thumb_' . $target_file_name;
$filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true));
$filterFileRename->filter($file_name);
$thumb = Base_Image_PhpThumbFactory::create($targetPath);
$thumb->resize(128, 84);
$thumb->save($targetPathThumb);
// file name
//.........这里部分代码省略.........
示例15: addCountryImageEXPAction
public function addCountryImageEXPAction()
{
$this->_helper->layout->disableLayout();
//$this->_helper->viewRenderer->setNoRender(true);
//get request variables
$id = $this->_getParam("id");
$page = $this->_getParam("page");
$selTab = $this->_getParam("tab", "tabs-7");
$this->view->cityId = $id;
//create image upload form
$uploadForm = new Admin_Form_CityImages();
$elements = $uploadForm->getElements();
$uploadForm->clearDecorators();
foreach ($elements as $element) {
$element->removeDecorator('label');
$element->removeDecorator('td');
$element->removeDecorator('tr');
$element->removeDecorator('row');
$element->removeDecorator('HtmlTag');
$element->removeDecorator('placement');
$element->removeDecorator('data');
}
$this->view->uploadForm = $uploadForm;
//selects country images to edit
$oldImageArr = array();
$oldImageSortingArr = array();
$lonelyPlanetCountryM = new Application_Model_LonelyPlanetCountry();
$lonelyPlanetCountryM = $lonelyPlanetCountryM->find($id);
if (false !== $lonelyPlanetCountryM) {
$oldImageArr = unserialize($lonelyPlanetCountryM->getImages());
//echo "<pre>";
//print_r($oldImageArr);
for ($oCnt = 0; $oCnt < count($oldImageArr); $oCnt++) {
$imgArr = $oldImageArr[$oCnt];
$imgArr["alt_text"] = "";
$imgArr["slide_link_url"] = "";
$imgArr["slide_link_target"] = "";
$imgArr["weight"] = $oCnt + 1;
$oldImageSortingArr[] = $imgArr;
}
//print_r($oldImageSortingArr);
//echo "</pre>";
//exit;
}
$request = $this->getRequest();
if ($request->isPost()) {
$options = $request->getPost();
if ($uploadForm->isValid($options)) {
$target_file_name = "";
//Upload image strat here
$upload = new Zend_File_Transfer_Adapter_Http();
if ($upload->isValid()) {
$upload->setDestination("media/picture/country/");
try {
$upload->receive();
} catch (Zend_File_Transfer_Exception $e) {
$msg = $e->getMessage();
}
$upload->setOptions(array('useByteString' => false));
$file_name = $upload->getFileName('countryImage');
$cardImageTypeArr = explode(".", $file_name);
$ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]);
$target_file_name = "country{$country_id}_" . time() . ".{$ext}";
$targetPath = "media/picture/country/images/" . $target_file_name;
$targetPathThumb = "media/picture/country/images/thumbs/" . $target_file_name;
$filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true));
$filterFileRename->filter($file_name);
$thumb = Base_Image_PhpThumbFactory::create($targetPath);
$thumb->resize(625, 330);
$thumb->save($targetPathThumb);
}
//end if
//upload image Ends here
//set country Image array
$addImageArr = array();
$addImageArr["image_caption"] = $options["slideTitle"];
$addImageArr["image_photographer"] = "Gap Daemon";
$addImageArr["image_filename"] = "/images/" . $target_file_name;
$addImageArr["image_thumbnail_filename"] = "/images/thumbs/" . $target_file_name;
$addImageArr["alt_text"] = $options["altText"];
$addImageArr["slide_link_url"] = $options["slideLinkUrl"];
$addImageArr["slide_link_target"] = $options["slideLinkTarget"];
$addImageArr["weight"] = $options["weight"];
$oldImageSortingArr[count($oldImageSortingArr)] = $addImageArr;
$newCountryImageArr = serialize($oldImageSortingArr);
$lonelyPlanetCountryM->setImages($newCountryImageArr);
$resImg = $lonelyPlanetCountryM->save();
if ($resImg) {
$_SESSION['errorMsg'] = "Images has been saved successfully.";
echo "<script>window.opener.location='/admin/featured-city/edit-country/id/{$id}/page/{$page}/tab/{$selTab}';</script>";
echo "<script>window.close();</script>";
} else {
$this->view->errorMsg = "Error occured, please try again later.";
}
} else {
$uploadForm->reset();
$uploadForm->populate($options);
}
}
//end if
//.........这里部分代码省略.........