用于创建图像的组件.需要上传图像.上传的图像应保存在组件创建


component for creating images.need to upload images .the images uploaded should be saved in component created

我正在创建一个用于在前端显示图像的Joomla 2.5组件。在管理方面,我需要使用一个文件上传器保存多个图像。谁能告诉我是谁做的吗?这是我编写的上传文件的函数。

        function fileUpload($max, $module_dir, $file_type, $msg){
          $file = JRequest::getVar('file_upload', null, 'files', 'array'); 
         if(isset($file)){ 
            //Clean up filename to get rid of strange characters like spaces etc
            $filename = JFile::makeSafe($file['name']);
            if($file['size'] > $max) $msg = JText::_('ONLY_FILES_UNDER').' '.$max;
            //Set up the source and destination of the file
            $src = $file['tmp_name'];
            $dest = $module_dir . DS . $filename;
            //First check if the file has the right extension, we need jpg only
            if ($file['type'] == $file_type || $file_type == '*') { 
               if ( JFile::upload($src, $dest) ) {
                   //Redirect to a page of your choice
                    $msg = JText::_('FILE_SAVE_AS').' '.$dest;
               } else {
                      //Redirect and throw an error message
                    $msg = JText::_('ERROR_IN_UPLOAD');
               }
            } else {
               //Redirect and notify user file is not right extension
                    $msg = JText::_('FILE_TYPE_INVALID');
            }
            $msg = "<script>alert('". $msg ."');</script>";
          }
          return $msg;
           }
        $user =& JFactory::getUser();
       $username = $user->get('username');
         $acc = 0;
         $session =& JFactory::getSession(); 
        if(isset($user_names)) {
      $more = strpos($user_names, ',',0);
        if($more >0){
            $user_names = explode(',',$user_names);
            foreach($user_names as $un){
                    if($un == $username) {
                            $session->set($acc, 1); 
                    }else{
                            $session->set($acc, 0); 
                    }
            }
           }else{
            if ($user_names == $username) $session->set($acc, 1); 
     }
   else{
    if(isset($username)) $session->set($acc, 1); 
    }
   if($session->get($acc) == 1){
    ?>

  <?php
    print fileUpload($max, $module_dir, $file_type, $msg);
  }

您可以使用SWF文件上传器使您的组件用于图像或文件上传功能。请看这个链接,它可能会有所帮助。

在组件中创建文件上传器

正如Tornado提到的,您可以使用SWFUpload脚本。然而,当我们尝试使用它时,它花了相当长的时间来集成,因为文档不是很好。因此,我决定在此基础上制作一个独立的组件,它很容易集成到第三方组件中,比如你的组件。如果你想使用它,你可以从这里下载:

http://joomjunk.co.uk/products/component-home/swfupload.html

还有一个小的文档选项卡,告诉您需要做什么以及要编辑哪些文件。

希望能有所帮助