Skip to main content
added 209 characters in body
Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71
<?php
class MageSf_OrderCustom_Adminhtml_SfuploadController extends Mage_Adminhtml_Controller_Action {  
    public function uploadAction() {
        if (isset($_FILES['docname']['name']) && $_FILES['docname']['name'] != '') {
            try {
                $uploader = new Varien_File_Uploader('docname');
                $uploader->setAllowedExtensions(array('doc','pdf','txt','docx'));
                $uploader->setAllowCreateFolders(true);
                $uploader->setAllowRenameFiles(false);
                $uploader->setFilesDispersion(false);
                $newDir = "customer_documents";

                $newdirPath = Mage::getBaseDir('media') . DS . "customer_documents";

                if (!file_exists($newdirPath)) {
                    mkdir($newdirPath, 0777);
                }

                $path = Mage::getBaseDir('media') . DS . $newDir . DS;
                $resizedPath = Mage::getBaseDir('media') . DS . $newDir;
                $uploader->save($path, $_FILES['docname']['name']);
 
            } catch (Exception $e $filename = $uploader->getUploadedFileName(); {// Uploaded File name
                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('core')->__('File uploaded successfully.'));
            } catch (Exception $e) {
        }
        Mage::getSingleton('adminhtml/session')->addError(Mage::helper('brandlogo''core')->__('Unable to find item to save'));
            }
        }
        
        $this->_redirectReferer();
    }
}
<?php
class MageSf_OrderCustom_Adminhtml_SfuploadController extends Mage_Adminhtml_Controller_Action {  
    public function uploadAction() {
        if (isset($_FILES['docname']['name']) && $_FILES['docname']['name'] != '') {
            try {
                $uploader = new Varien_File_Uploader('docname');
                $uploader->setAllowedExtensions(array('doc','pdf','txt','docx'));
                $uploader->setAllowCreateFolders(true);
                $uploader->setAllowRenameFiles(false);
                $uploader->setFilesDispersion(false);
                $newDir = "customer_documents";

                $newdirPath = Mage::getBaseDir('media') . DS . "customer_documents";

                if (!file_exists($newdirPath)) {
                    mkdir($newdirPath, 0777);
                }

                $path = Mage::getBaseDir('media') . DS . $newDir . DS;
                $resizedPath = Mage::getBaseDir('media') . DS . $newDir;
                $uploader->save($path, $_FILES['docname']['name']);
 
            } catch (Exception $e) {
                
            }
        }
        Mage::getSingleton('adminhtml/session')->addError(Mage::helper('brandlogo')->__('Unable to find item to save'));
        $this->_redirectReferer();
    }
}
<?php
class MageSf_OrderCustom_Adminhtml_SfuploadController extends Mage_Adminhtml_Controller_Action {  
    public function uploadAction() {
        if (isset($_FILES['docname']['name']) && $_FILES['docname']['name'] != '') {
            try {
                $uploader = new Varien_File_Uploader('docname');
                $uploader->setAllowedExtensions(array('doc','pdf','txt','docx'));
                $uploader->setAllowCreateFolders(true);
                $uploader->setAllowRenameFiles(false);
                $uploader->setFilesDispersion(false);
                $newDir = "customer_documents";

                $newdirPath = Mage::getBaseDir('media') . DS . "customer_documents";

                if (!file_exists($newdirPath)) {
                    mkdir($newdirPath, 0777);
                }

                $path = Mage::getBaseDir('media') . DS . $newDir . DS;
                $resizedPath = Mage::getBaseDir('media') . DS . $newDir;
                $uploader->save($path, $_FILES['docname']['name']);
                $filename = $uploader->getUploadedFileName(); // Uploaded File name
                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('core')->__('File uploaded successfully.'));
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')->addError(Mage::helper('core')->__('Unable to find item to save'));
            }
        }
        
        $this->_redirectReferer();
    }
}
deleted 393 characters in body
Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71

Create a controller file UploadControllerSfuploadController.php under MageSf/OrderCustom/controllers/Adminhtml

<?php
class MageSf_OrderCustom_Adminhtml_UploadControllerMageSf_OrderCustom_Adminhtml_SfuploadController extends Mage_Adminhtml_Controller_Action {  
    public function uploadAction() {
        if ($data = $this->getRequest()->getPost()) {
            if (isset($_FILES['docname']['name']) && $_FILES['docname']['name'] != '') {
                try {
                    $uploader = new Varien_File_Uploader('docname');
                    $uploader->setAllowedExtensions(array('doc','pdf','txt','docx'));
                    $uploader->setAllowCreateFolders(true);
                    $uploader->setAllowRenameFiles(false);
                    $uploader->setFilesDispersion(false);
                    $newDir = "customer_documents";

                    $newdirPath = Mage::getBaseDir('media') . DS . "customer_documents";

                    if (!file_exists($newdirPath)) {
                        mkdir($newdirPath, 0777);
                    }

                    $path = Mage::getBaseDir('media') . DS . $newDir . DS;
                    $resizedPath = Mage::getBaseDir('media') . DS . $newDir;
                    $uploader->save($path, $_FILES['docname']['name']);
                    $uploadeddocname = $uploader->getUploadedDocname();

                } catch (Exception $e) {
                    
                }
                $data['docname'] = $uploader->getUploadedDocname();
            }
        }
        Mage::getSingleton('adminhtml/session')->addError(Mage::helper('brandlogo')->__('Unable to find item to save'));
        $this->_redirectReferer();
    }
}

Update your ordercustom.phtml You need to remove all other code from this file.

<form id="doc-form" name="doc-form" method="post" action="<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/uploadsfupload/upload', array('_secure''form_key' => trueMage::getSingleton('core/session')->getFormKey())); ?>" enctype="multipart/form-data">
 <label>Upload Document</label>
 <input type="file" title="File" name="docname">
 <button type="submit" title="Save"><span>Upload</span></button>                    
 </form>

Create a controller file UploadController.php under MageSf/OrderCustom/controllers/Adminhtml

class MageSf_OrderCustom_Adminhtml_UploadController extends Mage_Adminhtml_Controller_Action {  
    public function uploadAction() {
        if ($data = $this->getRequest()->getPost()) {
            if (isset($_FILES['docname']['name']) && $_FILES['docname']['name'] != '') {
                try {
                    $uploader = new Varien_File_Uploader('docname');
                    $uploader->setAllowedExtensions(array('doc','pdf','txt','docx'));
                    $uploader->setAllowCreateFolders(true);
                    $uploader->setAllowRenameFiles(false);
                    $uploader->setFilesDispersion(false);
                    $newDir = "customer_documents";

                    $newdirPath = Mage::getBaseDir('media') . DS . "customer_documents";

                    if (!file_exists($newdirPath)) {
                        mkdir($newdirPath, 0777);
                    }

                    $path = Mage::getBaseDir('media') . DS . $newDir . DS;
                    $resizedPath = Mage::getBaseDir('media') . DS . $newDir;
                    $uploader->save($path, $_FILES['docname']['name']);
                    $uploadeddocname = $uploader->getUploadedDocname();

                } catch (Exception $e) {
                    
                }
                $data['docname'] = $uploader->getUploadedDocname();
            }
        }
        Mage::getSingleton('adminhtml/session')->addError(Mage::helper('brandlogo')->__('Unable to find item to save'));
        $this->_redirectReferer();
    }
}

Update your ordercustom.phtml

<form id="doc-form" name="doc-form" method="post" action="<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/upload/upload', array('_secure' => true)); ?>" enctype="multipart/form-data">
 <label>Upload Document</label>
 <input type="file" title="File" name="docname">
 <button type="submit" title="Save"><span>Upload</span></button>                    
 </form>

Create a controller file SfuploadController.php under MageSf/OrderCustom/controllers/Adminhtml

<?php
class MageSf_OrderCustom_Adminhtml_SfuploadController extends Mage_Adminhtml_Controller_Action {  
    public function uploadAction() {
        if (isset($_FILES['docname']['name']) && $_FILES['docname']['name'] != '') {
            try {
                $uploader = new Varien_File_Uploader('docname');
                $uploader->setAllowedExtensions(array('doc','pdf','txt','docx'));
                $uploader->setAllowCreateFolders(true);
                $uploader->setAllowRenameFiles(false);
                $uploader->setFilesDispersion(false);
                $newDir = "customer_documents";

                $newdirPath = Mage::getBaseDir('media') . DS . "customer_documents";

                if (!file_exists($newdirPath)) {
                    mkdir($newdirPath, 0777);
                }

                $path = Mage::getBaseDir('media') . DS . $newDir . DS;
                $resizedPath = Mage::getBaseDir('media') . DS . $newDir;
                $uploader->save($path, $_FILES['docname']['name']);

            } catch (Exception $e) {
                
            }
        }
        Mage::getSingleton('adminhtml/session')->addError(Mage::helper('brandlogo')->__('Unable to find item to save'));
        $this->_redirectReferer();
    }
}

Update your ordercustom.phtml You need to remove all other code from this file.

<form id="doc-form" name="doc-form" method="post" action="<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/sfupload/upload',array('form_key' => Mage::getSingleton('core/session')->getFormKey())); ?>" enctype="multipart/form-data">
 <label>Upload Document</label>
 <input type="file" title="File" name="docname">
 <button type="submit" title="Save"><span>Upload</span></button>                    
 </form>
added 1 character in body
Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71
<form id="doc-form" name="doc-form" method="post" action="<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/upload/upload', array('_secure' => true)); ?>" enctype="multipart/form-data">
 <label>Upload Document</label>
 <input type="file" title="File" name="docname">
 <button type="submit" title="Save"><span>Upload</span></button>                    
 </form>
<form id="doc-form" name="doc-form" method="post" action="<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/upload/upload', array('_secure' => true); ?>" enctype="multipart/form-data">
 <label>Upload Document</label>
 <input type="file" title="File" name="docname">
 <button type="submit" title="Save"><span>Upload</span></button>                    
 </form>
<form id="doc-form" name="doc-form" method="post" action="<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/upload/upload', array('_secure' => true)); ?>" enctype="multipart/form-data">
 <label>Upload Document</label>
 <input type="file" title="File" name="docname">
 <button type="submit" title="Save"><span>Upload</span></button>                    
 </form>
deleted 12 characters in body
Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71
Loading
edited body
Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71
Loading
added 7 characters in body
Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71
Loading
Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71
Loading