在joomla的自定义组件中上传多图像

时间:2012-10-17 05:40:09

标签: joomla image-uploading

我已经尝试了http://docs.joomla.org/Creating_a_file_uploader_in_your_component,但首先它显示了错误:500经过一些研究后我删除了代码

"'.$session->getName().'" : "'.$session->getId().'", "format" : "raw"

并且错误消失了。现在Image没有在任何地方上传(我已经设置了路径'/ images /'文件夹)我在上传图片PART 5的代码中混淆了我在哪里使用这段代码?

1 个答案:

答案 0 :(得分:1)

function storeImageFile()
    {
        jimport('joomla.filesystem.file');
        jimport('joomla.filesystem.folder' );

        $path = 'PATH_GOES_HERE'.'designs'.DS;

        $folder_permissions = "0755";
        $folder_permissions = octdec((int)$folder_permissions);

        //create folder if not exists
        if (!JFolder::exists($path)){
           JFolder::create($path, $folder_permissions);          
        }        

        $file           = JRequest::getVar('design_images', null, 'files', 

        $count = count($file['name']);

        for($i=0;$i<$count;$i++)
        {
            //$i is the array position of the $_FILES array

            if(empty($file['tmp_name'][$i]))
            {
                return false;
            }


            //Clean up filename to get rid of strange characters like spaces etc
            $filename = JFile::makeSafe($file['name'][$i]);

            //setting source and destination
            $temporary_name = $file['tmp_name'][$i];
            $filename       = str_replace(' ', '_', $file['name'][$i]);
            $dest           = $path.$filename;

            if(JFile::upload($temporary_name, $dest))
            {
                echo "File Upload Successful";
                return true;
            }

        }



    }