0

我正在创建一个用于在前端显示图像的 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);
  }
4

2 回答 2

0

您可以使用 SWF 文件上传器为您的组件制作图像或文件上传功能。请参阅此链接,它可能会有所帮助。

在组件中创建文件上传器

于 2013-01-04T14:24:51.013 回答
0

正如 Tornado 所提到的,您可以使用 SWFUpload 脚本。但是,当我们尝试使用它时,由于文档不是很好,因此需要很长时间才能集成。因此决定基于此制作一个独立组件,该组件易于集成到第三方组件中,例如您的组件。如果你想使用它,你可以从这里下载:

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

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

希望这可以帮助

于 2013-01-04T16:13:22.780 回答