本文整理汇总了PHP中Zend_File_Transfer_Adapter_Http::addFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_File_Transfer_Adapter_Http::addFilter方法的具体用法?PHP Zend_File_Transfer_Adapter_Http::addFilter怎么用?PHP Zend_File_Transfer_Adapter_Http::addFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_File_Transfer_Adapter_Http
的用法示例。
在下文中一共展示了Zend_File_Transfer_Adapter_Http::addFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _buildAdapter
/**
* Create a ZF HTTP file transfer adapter.
*
* @return void
*/
protected function _buildAdapter()
{
$storage = Zend_Registry::get('storage');
$this->_adapter = new Zend_File_Transfer_Adapter_Http($this->_adapterOptions);
$this->_adapter->setDestination($storage->getTempDir());
// Add a filter to rename the file to something Omeka-friendly.
$this->_adapter->addFilter(new Omeka_Filter_Filename());
}
示例2: _uploadPagepreview
private function _uploadPagepreview()
{
$miscConfig = Zend_Registry::get('misc');
$configTeaserSize = $this->_helper->config->getConfig('teaserSize');
$savePath = $this->_websiteConfig['path'] . $this->_websiteConfig['tmp'];
$fileMime = $this->_getMimeType();
switch ($fileMime) {
case 'image/png':
$newName = '.png';
break;
case 'image/jpg':
case 'image/jpeg':
$newName = '.jpg';
$this->_helper->session->imageQualityPreview = self::PREVIEW_IMAGE_OPTIMIZE;
break;
case 'image/gif':
$newName = '.gif';
break;
default:
return false;
break;
}
$newName = md5(microtime(1)) . $newName;
$newImageFile = $savePath . $newName;
$this->_uploadHandler->addFilter('Rename', array('target' => $newImageFile, 'overwrite' => true));
$result = $this->_uploadImages($savePath, false);
if ($result['error'] == false) {
Tools_Image_Tools::resize($newImageFile, $configTeaserSize ? $configTeaserSize : $miscConfig['pageTeaserSize'], true);
$result['src'] = $this->_helper->website->getUrl() . $this->_websiteConfig['tmp'] . $newName;
}
return $result;
}
示例3: updateProfileAction
/**
* Update profile Employee
* @return type
*/
public function updateProfileAction()
{
$this->view->headTitle('Update Profile');
$form = new Employee_Form_UpdateProfile();
$id = (int) $this->getParam('id', '');
if (!$id) {
$this->_helper->redirector('list-profile');
}
$employeeMapper = new Employee_Model_EmployeeMapper();
$result = $employeeMapper->findId($id);
if (!$result) {
$this->view->message = "Nhan vien khong ton tai";
return;
}
$this->view->form = $form;
//set up URL image
$adapter = new Zend_File_Transfer_Adapter_Http();
$uploadPath = APPLICATION_PATH . '/../public/images/avatar';
$adapter->setDestination($uploadPath);
$adapter->addFilter('Rename', $result->getEmployeeId() . '.jpg');
$this->view->fileName = $result->getEmployeeId() . '.jpg';
if (!$adapter->receive()) {
$messages = $adapter->getMessages();
}
$avatar = $adapter->getFileName();
$this->_processShowForm($form, $result);
if ($this->_processUpdateFormProfile($form)) {
echo "Update success";
$this->view->message = "Update success";
$params = array('id' => $id);
$this->_helper->redirector("show-profile", 'profile', 'employee', $params);
}
}
示例4: changeprofileimgAction
public function changeprofileimgAction()
{
if ($this->getRequest()->isPost()) {
if (!empty($_FILES['photo']['name'])) {
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination(Zend_Registry::get('profileImagesPath'));
$files = $adapter->getFileInfo();
$i = 1;
foreach ($files as $file => $info) {
if (!$adapter->isUploaded($file)) {
return $this->_redirect('/profile');
}
$extension = strtolower(end(explode('.', $info['name'])));
$name = time() . $this->_user->id . $i++ . "." . $extension;
$adapter->addFilter('Rename', array('target' => Zend_Registry::get('profileImagesPath') . $name, 'overwrite' => TRUE));
if (!$adapter->receive($info['name'])) {
$this->view->error = 'There was a problem uploading the photo. Please try again later';
return $this->render('error');
}
}
$filename = $adapter->getFileName();
$filename = basename($filename);
$changes = array('photo' => $filename);
$profileService = new Service_Profile();
if ($edited = $profileService->editProfile($this->_user->profileid, $changes)) {
return $this->_redirect('/profile');
} else {
$this->view->error = 'There was a problem updating your profile. Please try again later';
return $this->render('error');
}
}
} else {
$this->_redirect('/profile');
}
}
示例5: uploadAjaxAction
public function uploadAjaxAction()
{
$this->_helper->layout->setLayout('ajax');
$data = $this->_request->getPost();
$extraDados = "";
if (isset($data['id'])) {
$extraDados = $data['id'] . '-';
}
$path = PUBLIC_PATH . DIRECTORY_SEPARATOR . 'uploads';
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->setDestination($path);
// Returns all known internal file information
$files = $upload->getFileInfo();
foreach ($files as $file => $info) {
// Se não existir arquivo para upload
if (!$upload->isUploaded($file)) {
print '<p class="alert alert-warning">Nenhum arquivo selecionado para upload<p>';
continue;
} else {
$fileName = $extraDados . str_replace(' ', '_', strtolower($info['name']));
// Renomeando o arquivo
$upload->addFilter('Rename', array('target' => $path . DIRECTORY_SEPARATOR . $fileName, 'overwrite' => true));
}
// Validação do arquivo ?
if (!$upload->isValid($file)) {
print '<p class="alert alert-danger" > <b>' . $file . '</b>. Arquivo inválido </p>';
continue;
} else {
if ($upload->receive($info['name'])) {
print '<p class="alert alert-success"> Arquivo: <b>' . $info['name'] . '</b> enviado com sucesso e renomeado para: <b>' . $fileName . '</b> </p>';
}
}
}
}
示例6: uploadAction
public function uploadAction()
{
$project_id = $this->_request->getParam('id');
//Validate that project belongs to user here.
$project_helper = $this->_helper->Projects;
if ($project_helper->isOwner($this->user_session->id, $project_id, $this->project_model)) {
$adapter = new Zend_File_Transfer_Adapter_Http();
foreach ($adapter->getFileInfo() as $key => $file) {
//Get extension
$path = split("[/\\.]", $file['name']);
$ext = end($path);
try {
$adapter->addValidator('Extension', false, array('extension' => 'jpg,gif,png', 'case' => true));
//Should probably use the array method below to enable overwriting
$new_name = md5(rand()) . '-' . $project_id . '.' . $ext;
//Add rename filter
$adapter->addFilter('Rename', UPLOAD_PATH . $new_name);
} catch (Zend_File_Transfer_Exception $e) {
die($e->getMessage());
}
try {
//Store
if ($adapter->receive($file['name'])) {
$this->image_model->addOne($project_id, $new_name, $key);
}
} catch (Zend_File_Transfer_Exception $e) {
die($e->getMessage());
}
}
header("Location: /account/project/id/{$project_id}");
} else {
header("Location: /account");
}
}
示例7: handleUploadedFile
/**
* Handle the uploaded file
*
* @return string|boolean
*/
public function handleUploadedFile()
{
$upload = new Zend_File_Transfer_Adapter_Http();
$target = $this->getTargetFilename($upload->getFilename());
$upload->addFilter(new Zend_Filter_File_Rename(array('target' => $target)));
return $upload->receive() ? $target : false;
}
示例8: uploadphotoAction
public function uploadphotoAction()
{
if ($this->getRequest()->isPost()) {
if ($_FILES['photo']['name'][0] != '') {
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination(Zend_Registry::get('userImagesPath'));
$files = $adapter->getFileInfo();
$i = 1;
foreach ($files as $file => $info) {
if (!$adapter->isUploaded($file)) {
$this->view->sendConfirm = 'Problem uploading files';
return $this->render('error');
}
$extension = strtolower(end(explode('.', $info['name'])));
$name = time() . '4' . $i . "." . $extension;
$i++;
$adapter->addFilter('Rename', array('target' => Zend_Registry::get('userImagesPath') . $name, 'overwrite' => TRUE));
if (!$adapter->receive($info['name'])) {
return $this->render('error');
}
}
$filename = $adapter->getFileName();
$filename = basename($filename);
$profile = array('photo' => $filename);
if (($edited = $this->profileService->editProfile(2, $profile)) === TRUE) {
$this->view->profile = $this->profileService->fetchProfile(2);
} else {
$this->view->profile = $edited;
}
$this->render('getprofile');
}
}
}
示例9: upload
public function upload($params = array())
{
if (!is_dir($params['destination_folder'])) {
mkdir($params['destination_folder'], 0777, true);
}
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($params['destination_folder']);
$adapter->setValidators($params['validators']);
if ($adapter->getValidator('ImageSize')) {
$adapter->getValidator('ImageSize')->setMessages(array('fileImageSizeWidthTooBig' => $this->_('Image too large, %spx maximum allowed.', '%maxwidth%'), 'fileImageSizeWidthTooSmall' => $this->_('Image not large enough, %spx minimum allowed.', '%minwidth%'), 'fileImageSizeHeightTooBig' => $this->_('Image too high, %spx maximum allowed.', '%maxheight%'), 'fileImageSizeHeightTooSmall' => $this->_('Image not high enough, %spx minimum allowed.', '%minheight%'), 'fileImageSizeNotDetected' => $this->_("The image size '%s' could not be detected.", '%value%'), 'fileImageSizeNotReadable' => $this->_("The image '%s' does not exist", '%value%')));
}
if ($adapter->getValidator('Size')) {
$adapter->getValidator('Size')->setMessages(array('fileSizeTooBig' => $this->_("Image too large, '%s' allowed.", '%max%'), 'fileSizeTooSmall' => $this->_("Image not large enough, '%s' allowed.", '%min%'), 'fileSizeNotFound' => $this->_("The image '%s' does not exist", '%value%')));
}
if ($adapter->getValidator('Extension')) {
$adapter->getValidator('Extension')->setMessages(array('fileExtensionFalse' => $this->_("Extension not allowed, '%s' only", '%extension%'), 'fileExtensionNotFound' => $this->_("The file '%s' does not exist", '%value%')));
}
$files = $adapter->getFileInfo();
$return_file = '';
foreach ($files as $file => $info) {
//Créé l'image sur le serveur
if (!$adapter->isUploaded($file)) {
throw new Exception($this->_('An error occurred during process. Please try again later.'));
} else {
if (!$adapter->isValid($file)) {
if (count($adapter->getMessages()) == 1) {
$erreur_message = $this->_('Error : <br/>');
} else {
$erreur_message = $this->_('Errors : <br/>');
}
foreach ($adapter->getMessages() as $message) {
$erreur_message .= '- ' . $message . '<br/>';
}
throw new Exception($erreur_message);
} else {
$new_name = uniqid("file_");
if (isset($params['uniq']) and $params['uniq'] == 1) {
if (isset($params['desired_name'])) {
$new_name = $params['desired_name'];
} else {
$format = pathinfo($info["name"], PATHINFO_EXTENSION);
if (!in_array($format, array("png", "jpg", "jpeg", "gif"))) {
$format = "jpg";
}
$new_name = $params['uniq_prefix'] . uniqid() . ".{$format}";
}
$new_pathname = $params['destination_folder'] . '/' . $new_name;
$adapter->addFilter(new Zend_Filter_File_Rename(array('target' => $new_pathname, 'overwrite' => true)));
}
$adapter->receive($file);
$return_file = $new_name;
}
}
}
return $return_file;
}
示例10: uploadAction
public function uploadAction()
{
if (!empty($_FILES)) {
try {
$path = '/var/apps/iphone/';
$base_path = Core_Model_Directory::getBasePathTo($path);
$filename = uniqid() . '.pem';
if (!is_dir($base_path)) {
mkdir($base_path, 0775, true);
}
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($base_path);
$adapter->setValidators(array('Extension' => array('pem', 'case' => false)));
$adapter->getValidator('Extension')->setMessages(array('fileExtensionFalse' => $this->_("Extension not allowed, \\'%s\\' only", '%extension%')));
$files = $adapter->getFileInfo();
foreach ($files as $file => $info) {
if (!$adapter->isUploaded($file)) {
throw new Exception($this->_('An error occurred during process. Please try again later.'));
} else {
if (!$adapter->isValid($file)) {
if (count($adapter->getMessages()) == 1) {
$erreur_message = $this->_('Error : <br/>');
} else {
$erreur_message = $this->_('Errors : <br/>');
}
foreach ($adapter->getMessages() as $message) {
$erreur_message .= '- ' . $message . '<br/>';
}
throw new Exception($erreur_message);
} else {
$adapter->addFilter(new Zend_Filter_File_Rename(array('target' => $base_path . $filename, 'overwrite' => true)));
$adapter->receive($file);
}
}
}
$certificat = new Push_Model_Certificat();
$certificat->find('ios', 'type');
if (!$certificat->getId()) {
$certificat->setType('ios');
}
$certificat->setPath($path . $filename)->save();
$datas = array('success' => 1, 'files' => 'eeeee', 'message_success' => $this->_('Infos successfully saved'), 'message_button' => 0, 'message_timeout' => 2);
} catch (Exception $e) {
$datas = array('error' => 1, 'message' => $e->getMessage());
}
$this->getLayout()->setHtml(Zend_Json::encode($datas));
}
}
示例11: imageAction
public function imageAction()
{
if ($this->getRequest()->isPost()) {
$upload = new Zend_File_Transfer_Adapter_Http();
$dirs = array('image' => array('gif', 'jpg', 'jpeg', 'png'), 'flash' => array('swf', 'flv'));
$dir = $this->_getParam('dir');
if (!isset($dirs[$dir])) {
$this->_alert('上传类型出错!');
}
$savePath = UPLOAD_PATH . DS . $dir;
//检查文件大小
$upload->addValidator('Size', false, 500000);
if (false == $upload->isValid()) {
$this->_alert('上传文件大小超过500KB限制。');
}
//检查目录
if (@is_dir($savePath) === false) {
$this->_alert('上传目录不存在。');
}
//检查目录写权限
if (@is_writable($savePath) === false) {
$this->_alert('上传目录没有写权限。');
}
//获得文件类型
$upload->addValidator('Extension', false, $dirs[$dir]);
if (false == $upload->isValid()) {
$this->_alert('只能上传' . implode('、', $dirs[$dir]) . '文件类型');
}
//设置保存的Path
$upload->setDestination($savePath);
//设置新的文件名
$fileInfo = $upload->getFileInfo();
$tmpFile = $fileInfo['imgFile']['name'];
$extension = explode('.', $tmpFile);
$extension = array_pop($extension);
$newFile = md5($tmpFile . uniqid()) . '.' . $extension;
$upload->addFilter('Rename', array('target' => $savePath . DS . $newFile, 'overwrite' => true));
//保存文件
$upload->receive();
//返回文件url
echo Zend_Json::encode(array('error' => 0, 'url' => $this->view->baseUrl() . '/uploads/image/' . $newFile));
exit;
} else {
$this->_alert('请选择文件。');
exit;
}
}
示例12: save
public function save($path, $extension, $userid = 0)
{
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination($path);
$files = $adapter->getFileInfo();
foreach ($files as $file => $info) {
if (!$adapter->isUploaded($file)) {
return false;
}
$filename = $this->generateFileName($extension, $userid);
$adapter->addFilter('Rename', array('target' => $path . $filename, 'overwrite' => TRUE));
if (!$adapter->receive($info['name'])) {
return false;
}
}
$filename = $adapter->getFileName();
$filename = basename($filename);
return $filename;
}
示例13: uploadAction
public function uploadAction()
{
$this->disableMvc(true, true);
$account = new Model_Account();
$adapter = new Zend_File_Transfer_Adapter_Http();
if (!is_dir(ROOT_PATH . '/public/files/tmp/')) {
mkdir(ROOT_PATH . '/public/files/tmp/');
}
$adapter->setDestination(ROOT_PATH . '/public/files/tmp/');
$info = $adapter->getFileInfo();
$ex = explode('.', $info['Filedata']['name']);
$fileType = $ex[count($ex) - 1];
$hash = $adapter->getHash('md5');
$tmpFile = $info['Filedata']['destination'] . '/' . $hash . '.' . $fileType;
$adapter->addFilter('Rename', array('target' => $tmpFile, 'overwrite' => true));
if ($adapter->receive()) {
$img = new Unodor_Image_Resize($tmpFile);
$img->adaptiveResize(50, 50)->save($tmpFile, false);
echo $hash . '.' . $fileType;
}
}
示例14: upload
/**
* 上传图片处理方法,
* 还有中文bug
*/
public function upload($fileDir, $imgpath)
{
$adapter = new Zend_File_Transfer_Adapter_Http();
// 不需要渲染模板页
$this->getFrontController()->setParam('noViewRenderer', true);
// 你存放上传文件的文件夹
$adapter->setDestination($fileDir);
$adapter->addValidator('Extension', false, 'gif,jpeg,png,jpg');
//设置上传文件的后缀名
$adapter->addValidator('Count', false, array('min' => 1, 'max' => 5));
//设置上传文件的个数
$adapter->addValidator('ImageSize', false, array('minwidth' => 0, 'maxwidth' => 40960, 'minhight' => 0, 'maxhight' => 40960));
////设置上传图片的大小
$adapter->addValidator('FilesSize', false, array('min' => '4KB', 'max' => '4096KB'));
////设置上传文件的大小
//添加过滤器来修改上传文件的名称
if ($imgpath) {
$adapter->addFilter('Rename', array('target' => $imgpath, 'overwrite' => true));
}
/* $fileInfo = $this->adapter->getFileInfo();
foreach ($fileInfo as $file=>$info) { //file-文件名
if ($this->adapter->isValid($file)) {
var_dump($info);die;
}
} */
// 返回上传后出现在信息
if (!$adapter->receive()) {
/* $messages = $adapter->getMessages ();
echo implode ( "n", $messages ); */
$out[Response::ERRNO] = 0;
$out[Response::MSG] = '上传成功!';
Response::out($out);
exit;
} else {
$out[Response::ERRNO] = 1;
$out[Response::MSG] = '上传失败!';
Response::out($out);
exit;
}
}
示例15: saveAction
/**
* Enter description here ...
*/
public function saveAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$post = $this->getRequest()->getPost();
$data = array('name' => $post['name'], 'alias' => $post['alias'], 'link' => $post['link'], 'sort' => $post['sort'], 'description' => $post['desc']);
if (isset($post['active'])) {
$data['active'] = 1;
}
if ($_FILES['icon']['name'] != '') {
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->setDestination($_SERVER['DOCUMENT_ROOT'] . "/upload/icons/");
$name = $upload->getFileName('icon', false);
$ext = split("\\.", $name);
$newName = md5($name) . '.' . $ext[count($ext) - 1];
$upload->addFilter('Rename', array('target' => $_SERVER['DOCUMENT_ROOT'] . "/upload/icons/" . $newName, 'overwrite' => true));
try {
$upload->receive();
$data['logo'] = $newName;
} catch (Zend_File_Transfer_Exception $e) {
$e->getMessage();
}
}
//Zend_Debug::dump($post);
$intro = new Intro();
if ($post['id'] == "") {
$intro->insertIntro($data);
} else {
$intro->updateIntro($data, $post['id']);
}
if ($post['savenew'] == 0) {
$this->_redirect('admin/intro/show');
} else {
$this->_redirect('admin/intro/new');
}
}