本文整理汇总了PHP中Varien_File_Uploader::checkMimeTypeCustom方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_File_Uploader::checkMimeTypeCustom方法的具体用法?PHP Varien_File_Uploader::checkMimeTypeCustom怎么用?PHP Varien_File_Uploader::checkMimeTypeCustom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_File_Uploader
的用法示例。
在下文中一共展示了Varien_File_Uploader::checkMimeTypeCustom方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tradepostAction
public function tradepostAction()
{
if ($_FILES['businessfile']['size'] > 5242880) {
Mage::getSingleton('customer/session')->addError('Please upload file size 5MB max.');
Mage::getSingleton('core/session')->setThankyouerror('1');
$this->_redirect('*/*/trade');
return;
}
if (isset($_FILES['businessfile']['name']) && $_FILES['businessfile']['name'] != '') {
try {
$customer = Mage::getSingleton('customer/session')->getCustomer();
//$company = $this->getRequest()->getPost('buscompany');
$path = Mage::getBaseDir() . DS . 'customer_business_doc' . DS;
//desitnation directory
$archpath = Mage::getBaseDir() . DS . 'customer_business_doc' . DS . 'archieves' . DS;
$fname = $_FILES['businessfile']['name'];
//file name
$uploader = new Varien_File_Uploader('businessfile');
//load class
$uploader->setAllowedExtensions(array('doc', 'pdf', 'odt', 'docx', 'png', 'jpeg', 'jpg', 'tiff'));
//Allowed extension for file
$uploader->checkMimeTypeCustom(array('application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/pdf', 'application/vnd.oasis.opendocument.text', 'image/png', 'image/jpeg', 'image/tiff'));
//$uploader->setAllowCreateFolders(true); //for creating the directory if not exists
$uploader->setAllowRenameFiles(true);
//if true, uploaded file's name will be changed, if file with the same name already exists directory.
$uploader->setFilesDispersion(false);
$output = $uploader->save($path, $fname);
//save the file on the specified path
//print_r($output); exit;
$model = Mage::getModel('docupload/docupload');
$model->setUserId($customer->getId());
$model->setName($customer->getFirstname() . ' ' . $customer->getLastname());
$model->setFilename($output['file']);
$model->setNewDocs(1);
$model->setDocumentType($this->getRequest()->getPost('docu_type'));
//$model->setOwnershipType($this->getRequest()->getPost('owner-type'));
//$model->setNatureOfBusiness($this->getRequest()->getPost('business-nature'));
$model->save();
$customer->setZiscorporate(816);
//$customer->setCompany($company);
$customer->save();
Mage::getSingleton('customer/session')->addSuccess('File uploaded successfully and your verification is pending from zoffio side.');
$collection = Mage::getModel('docupload/docupload')->getCollection()->addFieldToFilter('user_id', $customer->getId())->setOrder('id', 'DESC');
if (count($collection->getData()) > 1) {
$i = 1;
foreach ($collection as $doc) {
if ($i > 1) {
$model = Mage::getModel('docupload/docupload')->load($doc->getId());
$model->setNewDocs(0);
$model->save();
}
$filename = $doc->getFilename();
if ($fname != $filename) {
if ($i > 1) {
if (copy($path . $filename, $archpath . $filename)) {
$delete[] = $path . $filename;
}
foreach ($delete as $file) {
unlink($file);
}
}
if ($i >= 5) {
unlink($archpath . $filename);
}
}
$i++;
}
}
//echo $output['file']; exit;
} catch (Exception $e) {
//echo 'Error Message: '.$e->getMessage();
//Mage::throwException('Error Message: '.$e->getMessage());
Mage::getSingleton('customer/session')->addError($e->getMessage());
Mage::getSingleton('core/session')->setThankyouerror('1');
$this->_redirect('*/*/trade');
return;
}
} else {
if ($_FILES['businessfile']['name'] == "") {
Mage::getSingleton('customer/session')->addError('Please upload file.');
Mage::getSingleton('core/session')->setThankyouerror('1');
$this->_redirect('*/*/trade');
return;
}
}
Mage::getSingleton('core/session')->setTradesuccess('1');
$this->_redirect('*/*/tradeSuccess');
return;
}
示例2: saveAction
/**
* Save customer action
*/
public function saveAction()
{
$data = $this->getRequest()->getPost();
$this->_initCustomer('customer_id');
$customer = Mage::registry('current_customer');
//echo $_FILES['business_file']['name'];
//echo "<pre>"; print_r($data); echo "</pre>"; exit;
if (isset($_FILES['business_file']['name']) && $_FILES['business_file']['name'] != '' && $_FILES['business_file']['size'] < 5242880) {
try {
//$company = $data['business_company'];
$path = Mage::getBaseDir() . DS . 'customer_business_doc' . DS;
//desitnation directory
$archpath = Mage::getBaseDir() . DS . 'customer_business_doc' . DS . 'archieves' . DS;
$fname = $_FILES['business_file']['name'];
//file name
$uploader = new Varien_File_Uploader('business_file');
//load class
$uploader->setAllowedExtensions(array('doc', 'pdf', 'odt', 'docx', 'png', 'jpeg', 'jpg', 'tiff'));
//Allowed extension for file
$uploader->checkMimeTypeCustom(array('application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/pdf', 'application/vnd.oasis.opendocument.text', 'image/png', 'image/jpeg', 'image/tiff'));
$uploader->setAllowRenameFiles(true);
//if true, uploaded file's name will be changed, if file with the same name already exists directory.
$uploader->setFilesDispersion(false);
$output = $uploader->save($path, $fname);
//save the file on the specified path
//print_r($output); exit;
$model = Mage::getModel('docupload/docupload');
$model->setUserId($customer->getId());
$model->setName($customer->getFirstname() . ' ' . $customer->getLastname());
$model->setFilename($output['file']);
$model->setNewDocs(1);
$model->setDocumentType($data['document_type']);
$model->setOwnershipType($data['ownership_type']);
$model->setNatureOfBusiness($data['nature_of_business']);
$model->save();
$customer->setZiscorporate(816);
//$customer->setCompany($company);
$customer->save();
Mage::getSingleton('adminhtml/session')->addSuccess('File uploaded successfully and your verification is pending from zoffio side.');
$collection = Mage::getModel('docupload/docupload')->getCollection()->addFieldToFilter('user_id', $customer->getId())->setOrder('id', 'DESC');
if (count($collection->getData()) > 1) {
$i = 1;
foreach ($collection as $doc) {
if ($i > 1) {
$model = Mage::getModel('docupload/docupload')->load($doc->getId());
$model->setNewDocs(0);
$model->save();
}
$filename = $doc->getFilename();
if ($fname != $filename) {
if ($i > 1) {
if (copy($path . $filename, $archpath . $filename)) {
$delete[] = $path . $filename;
}
foreach ($delete as $file) {
unlink($file);
}
}
if ($i >= 5) {
unlink($archpath . $filename);
}
}
$i++;
}
}
//echo $output['file']; exit;
} catch (Exception $e) {
//echo 'Error Message: '.$e->getMessage();
//Mage::throwException('Error Message: '.$e->getMessage());
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/');
return;
}
}
if ($data) {
$redirectBack = $this->getRequest()->getParam('back', false);
//$this->_initCustomer('customer_id');
/** @var $customer Mage_Customer_Model_Customer */
//$customer = Mage::registry('current_customer');
/** @var $customerForm Mage_Customer_Model_Form */
$customerForm = Mage::getModel('customer/form');
$customerForm->setEntity($customer)->setFormCode('adminhtml_customer')->ignoreInvisible(false);
$formData = $customerForm->extractData($this->getRequest(), 'account');
// Handle 'disable auto_group_change' attribute
if (isset($formData['disable_auto_group_change'])) {
$formData['disable_auto_group_change'] = empty($formData['disable_auto_group_change']) ? '0' : '1';
}
$errors = $customerForm->validateData($formData);
if ($errors !== true) {
foreach ($errors as $error) {
$this->_getSession()->addError($error);
}
$this->_getSession()->setCustomerData($data);
$this->getResponse()->setRedirect($this->getUrl('*/customer/edit', array('id' => $customer->getId())));
return;
}
$customerForm->compactData($formData);
//.........这里部分代码省略.........