Magento前端的文件上传

时间:2013-09-13 04:47:42

标签: magento magento-1.7 magento-1.6

我想为客户设置个人资料图片,我从我的帐户标签上传图片,并为我们的自定义模块个人资料分别设置标签。当从.phtml发送图像时,$ _FILES的数组是空的,所以我的问题是如何在我的代码中为我的代码设置客户端的配置文件图像是在我的saveimageAction中。那么他们在做什么呢?

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/')); 

    }

1 个答案:

答案 0 :(得分:1)

检查html out put并确保表单“enctype”属性低于给定值

<form action="your_controller_action" method="post" enctype="multipart/form-data">