1

I am Creating an image attachment for each order in admin panel. I have used the image up loader and saved that images to a custom directory as follows:

 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','png'));
            $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']);
            echo $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'));
        }
    }

But Now I want to save this image to the current order table in database and then i will show it on the account page each user who's order it will be.

This is my tab in order view page admin panel:

class MageSf_OrderCustom_Block_Adminhtml_Order_View_Tab_OrderCustom
extends Mage_Adminhtml_Block_Template
implements Mage_Adminhtml_Block_Widget_Tab_Interface
{    
//change _constuct to _construct()
public function _construct()
{
    parent::_construct();
    $this->setTemplate('magsf/ordercustom/order/view/tab/ordercustom.phtml');

}

public function getTabLabel() {
    return $this->__('Order Attachment');
}

public function getTabTitle() {
    return $this->__('Order Attachment');
}

public function canShowTab() {
    return true;
}

public function isHidden() {
    return false;
}

public function getOrder(){
    return Mage::registry('current_order');
}
}  

And here is my form that for uploading the image:

<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>
1

First add order id in your form

$this->getOrder()->getId()

<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(),'order_id'=>$this->getOrder()->getId())); ?>" 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>

in your uploadAction

$orderid= $this->getRequest()->getParam('order_id');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.