本文整理汇总了PHP中Zend_File_Transfer_Adapter_Http::isUploaded方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_File_Transfer_Adapter_Http::isUploaded方法的具体用法?PHP Zend_File_Transfer_Adapter_Http::isUploaded怎么用?PHP Zend_File_Transfer_Adapter_Http::isUploaded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_File_Transfer_Adapter_Http
的用法示例。
在下文中一共展示了Zend_File_Transfer_Adapter_Http::isUploaded方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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>';
}
}
}
}
示例2: 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');
}
}
}
示例3: handleUpload
/**
* @param string $attributeCode
* @param string $type
* @return bool
*/
protected static function handleUpload($attributeCode, $type)
{
if (!isset($_FILES)) {
return false;
}
$adapter = new Zend_File_Transfer_Adapter_Http();
if ($adapter->isUploaded('typecms_' . $attributeCode . '_')) {
if (!$adapter->isValid('typecms_' . $attributeCode . '_')) {
Mage::throwException(Mage::helper('typecms')->__('Uploaded ' . $type . ' is invalid'));
}
$upload = new Varien_File_Uploader('typecms[' . $attributeCode . ']');
$upload->setAllowCreateFolders(true);
if ($type == 'image') {
$upload->setAllowedExtensions(array('jpg', 'gif', 'png'));
}
$upload->setAllowRenameFiles(true);
$upload->setFilesDispersion(false);
try {
if ($upload->save(Mage::helper('typecms')->getBaseImageDir())) {
return $upload->getUploadedFileName();
}
} catch (Exception $e) {
Mage::throwException('Uploaded ' . $type . ' is invalid');
}
}
return false;
}
示例4: 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!');
}
}
示例5: 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');
}
}
示例6: 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;
}
示例7: indexAction
/**
* indexAction
* @author Thomas Schedler <tsh@massiveart.com>
* @version 1.0
*/
public function indexAction()
{
try {
$this->core->logger->debug('media->controllers->UploadController->indexAction()');
$this->objUpload = new Zend_File_Transfer_Adapter_Http();
/**
* 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!');
// }
if ($this->getRequest()->isPost()) {
$objRequest = $this->getRequest();
$this->intParentId = $objRequest->getParam('folderId');
/**
* check if is image or else document
*/
if ($this->intParentId > 0 && $this->intParentId != '') {
if (strpos($this->objUpload->getMimeType(self::UPLOAD_FIELD), 'image/') !== false) {
$this->handleImageUpload();
} else {
$this->handleFileUpload();
}
}
}
} catch (Exception $exc) {
$this->core->logger->err($exc);
}
}
示例8: uploadPreviewImage
/**
* Upload preview image
*
* @param string $scope the request key for file
* @param string $destinationPath path to upload directory
* @return bool
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function uploadPreviewImage($scope, $destinationPath)
{
if (!$this->_transferAdapter->isUploaded($scope)) {
return false;
}
if (!$this->_transferAdapter->isValid($scope)) {
throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Uploaded image is not valid'));
}
$upload = $this->_uploaderFactory->create(['fileId' => $scope]);
$upload->setAllowCreateFolders(true);
$upload->setAllowedExtensions($this->_allowedExtensions);
$upload->setAllowRenameFiles(true);
$upload->setFilesDispersion(false);
if (!$upload->checkAllowedExtension($upload->getFileExtension())) {
throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Invalid image file type.'));
}
if (!$upload->save($destinationPath)) {
throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Image can not be saved.'));
}
return $destinationPath . '/' . $upload->getUploadedFileName();
}
示例9: actionInstall
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'));
}
示例10: actionXenGallerySave
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)));
}
示例11: uploadAction
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));
}
}
示例12: actionImport
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'));
}
示例13: 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;
}
示例14: upload
private function upload()
{
$todir = $this->_cfg['temp']['path'] . $this->getRequest()->getParam('docid', 'unknown_doc');
if (!file_exists($todir)) {
mkdir($todir);
}
$adapter = new Zend_File_Transfer_Adapter_Http(array('ignoreNoFile' => true));
$filename = $adapter->getFileName('upload', false);
$adapter->addValidator('Extension', false, $this->getRequest()->getParam('type') == 'images' ? $this->imgExts : $this->fileExts)->addValidators($this->getRequest()->getParam('type') == 'images' ? $this->imgValidators : $this->fileValidators)->addFilter('Rename', array('target' => $todir . DIRECTORY_SEPARATOR . iconv('utf-8', FS_CHARSET, $filename), 'overwrite' => true));
// $adapter->setDestination($todir);
$result = new stdClass();
$result->messages = array();
$result->uploadedUrl = '';
if (!$adapter->isValid()) {
$result->messages = $adapter->getMessages();
} else {
if ($adapter->receive() && $adapter->isUploaded()) {
$result->uploadedUrl = ($this->getRequest()->getParam('type') == 'images' ? '' : 'downloads/') . $filename;
}
}
$result->CKEditorFuncNum = $this->getRequest()->getParam('CKEditorFuncNum');
return $result;
}
示例15: _uploadFiles
/**
* Handler for files uploader
* @return array
*/
private function _uploadFiles($savePath = null)
{
$this->_uploadHandler->clearValidators();
$this->_uploadHandler->clearFilters();
if (!$savePath) {
$savePath = $this->_getSavePath();
}
$fileInfo = $this->_uploadHandler->getFileInfo();
$file = reset($fileInfo);
preg_match('~[^\\x00-\\x1F"<>\\|:\\*\\?/]+\\.[\\w\\d]{2,8}$~iU', $file['name'], $match);
if (!$match) {
return array('result' => 'Corrupted filename', 'error' => true);
}
$this->_uploadHandler->addFilter('Rename', array('target' => $savePath . DIRECTORY_SEPARATOR . $file['name'], 'overwrite' => true));
if ($this->_uploadHandler->isUploaded() && $this->_uploadHandler->isValid()) {
try {
$this->_uploadHandler->receive();
} catch (Exceptions_SeotoasterException $e) {
$response = array('result' => $e->getMessage(), 'error' => true);
}
}
$response = array('result' => $this->_uploadHandler->getMessages(), 'error' => !$this->_uploadHandler->isReceived());
return $response;
}