Domanda

i want set profile image for customer and i upload image from my account tab and set tab separate for our custom module profile. when sent the image from .phtml then the array of $_FILES is empty so my question is that how set profile image for customer in magento my code is in my saveimageAction. so one they doing work on that?

print_r($_FILES);exit();
      if(isset($_FILES['profileimage']['name']) && ($_FILES['profileimage']['tmp_name'] != NULL))
  {
      $uploader = new Varien_File_Uploader('file');
      $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); 
      $uploader->setAllowRenameFiles(true);
      $uploader->setFilesDispersion(true);        
      $path = Mage::getBaseDir('media') . DS ;
      //$path= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);     

      $path = $path ."supportportal/avatar";
      $uploader->save($path, $_FILES['profileimage']['name']);

      $simage = Mage::getModel('supportportal/profile');
      $simage->setData('user_id',$getuserid);
      $simage->setData('image', $userimage);
      $simage->setData('created_date',date('d-m-Y H:i:s'));
      $simage->setData('last_updated_date',date('d-m-Y H:i:s'));
      $simage->setData('status',1);
      $simage->save();
    Mage::getSingleton('core/session')->addSuccess( $this->__('Image is Successfully Save!') );
    Mage::app()->getResponse()->setRedirect(Mage::getUrl('supportportal/index/profile/')); 

    }else{

        Mage::getSingleton('core/session')->addError( $this->__('Image Saving Error!') );
    Mage::app()->getResponse()->setRedirect(Mage::getUrl('supportportal/index/profile/')); 

    }
È stato utile?

Soluzione

Check the html out put and make sure the form "enctype" attribute has below given value

<form action="your_controller_action" method="post" enctype="multipart/form-data">
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top