Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Custom Module with image upload feature at Admin panel
 
davion
Jr. Member
 
Total Posts:  18
Joined:  2008-05-03
 

Well, first of all, I’ve been working on creating a custom module that provide news but with images feature.
Thus I want to be able to publish news with images. and handle them same way as product images.
As base I was using this wiki: http://www.magentocommerce.com/wiki/custom_module_with_custom_database_table

To let upload images same
basically I’ve add one more “Tab” at admin panel in Item Edit page this way:

/app/code/local/<Namespace>/<Module>/Block/Adminhtml/<Module>/Edit/Tabs.php

$this->addTab('content_section', array(
            
'label'     => Mage::helper('<module>')->__('Item Images'),
            
'title'     => Mage::helper('<module>')->__('Item Images'),
            
'content'   => $this->getLayout()->createBlock('<module>/adminhtml_<module>_edit_tab_content')->toHtml(),
        ));
and put file Content.php from
/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery/
to
/app/code/local/<Namespace>/<Module>/Block/Adminhtml/<Module>/Edit/Tabs/

here I’ve expected to get same image upload form (at least display it till now)
but got error:
Fatal error: Call to a member function getDataObject() on a non-object in /var/www/stigma/app/code/local/Virt/Areas/Block/Adminhtml/Areas/Edit/Tab/Content.php on line 156

 
Magento Community Magento Community
Magento Community
Magento Community
 
davion
Jr. Member
 
Total Posts:  18
Joined:  2008-05-03
 

ok, is there a way to provide image upload at custom module in admin panel?

What I’m trying to do for now is creating new <INPUT TYPE="FILE"> field at Item Edit page:
/app/code/local/<Namespace>/<Module>/Block/Adminhtml/<Module>/Edit/Tab/Form.php

.....
        
$fieldset->addField('imgfile''file', array(
            
'label'     => Mage::helper('<module>')->__('Title'),
            
'class'     => 'required-entry',
            
'required'  => true,
            
'name'      => 'imgfile',
        ));
......
and trying to get result of uploaded file at Controller:
/app/code/local/<Namespace>/<Module>/controllers/Adminhtml/<Module>Controller.php
...................
   public function 
saveAction()
    
{
        
if ( $this->getRequest()->getPost() ) {
            
try {
                $postData 
$this->getRequest()->getPost();
                $<
module>Model Mage::getModel('<module>/<module>');

         
/* START TO CHECK FOR FILE UPLOAD */
   
          
$filename1 $_FILES['imgfile']['tmp_name'];  
          
$filename2 $postData['imgfile'];

        
/* END */

                
$<module>Model->setId($this->getRequest()->getParam('id'))
                    ->
setTitle($postData['title'])
                    ->
setContent($postData['content'])
                    ->
setStatus($postData['status'])
                    ->
save();
                
                
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved'));
                
Mage::getSingleton('adminhtml/session')->set<Module>Data(false);
 
                
$this->_redirect('*/*/');
                return;
            
catch (Exception $e{
                Mage
::getSingleton('adminhtml/session')->addError($e->getMessage());
                
Mage::getSingleton('adminhtml/session')->set<Module>Data($this->getRequest()->getPost());
                
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
                return;
            
}
        }
        $this
->_redirect('*/*/');
    
}
..............

thus I get file name at variable $postData[’imgfile’]
but array
$_FILES are empty and I get error about :(

Any ideas how to upload file?

 
Magento Community Magento Community
Magento Community
Magento Community
 
davion
Jr. Member
 
Total Posts:  18
Joined:  2008-05-03
 

ok, finally I’ve done with image upload.

I did it by setting template <temp-name>.phtml to one more Tab at product edit page where
I can handle whatever I want.

But it’s not a Magento style.

Also it’s almost works for me with Magento way, by adding a field at edit form:

$fieldset->addField('filename''image', array(
          
'label'     => Mage::helper('pictos')->__('Image'),
          
'required'  => false,
          
'name'      => 'filename',
        ));

but I’ve got an error:
Warning: preg_match() expects parameter 2 to be string, array given in /var/www/lib/Varien/Data/Form/Element/Image.php on line 55

I’ve check this code but not found any serious problem with.
If anyone knows the problem -> helps appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Syndia
Member
 
Total Posts:  38
Joined:  2008-04-01
Netherlands, The
 

I’m also searching for this about three days in every topic, but still not found anything how-to create a custom tab in the product edit form.

I hope there is anybody who can help…

 
Magento Community Magento Community
Magento Community
Magento Community
 
davion
Jr. Member
 
Total Posts:  18
Joined:  2008-05-03
 

What exactly you want to do? Probably I can help.

Just create a custom Tab or fill it with some data?

 
Magento Community Magento Community
Magento Community
Magento Community
 
schmelzgeist
Sr. Member
 
Total Posts:  92
Joined:  2008-05-27
Marzipane World Capital (Lübeck, Germany)
 

i for one need a custom tab with the images upload capabilities but i didn’t seem to get it work right now :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
somesid
Sr. Member
 
Total Posts:  83
Joined:  2008-06-20
 

Solution posted here : http://www.magentocommerce.com/boards/viewthread/11667/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top