【问题标题】:Joomla custom user extensionJoomla 自定义用户扩展
【发布时间】:2011-08-08 11:22:49
【问题描述】:

我正在为高级前端用户界面编写 Joomla 1.5 扩展。 现在我必须添加一个功能,以便用户可以在前端上传图片并将其添加到他们的帐户中。

是否有标准的 Joomla 图片上传可用?

谢谢

【问题讨论】:

    标签: php joomla joomla1.5 joomla-extensions


    【解决方案1】:

    这是我的代码:(还有一些我不能在这里粘贴所有内容)

    function deleteLogo($logo)
    {
    
        // define path to file to delete
        $filePath =  'images/stories/members/' . $logo;
        $imagePath =  'images/stories/members/image/' . $image;
    
        // check if files exists
        $fileExists = JFile::exists($filePath);
        $imageExists = JFile::exists($imagePath);
        if($fileExists)
        {
            // attempt to delete file
            $fileDeleted = JFile::delete($filePath);
        }   
    
        if($imageExists)
        {
            // attempt to delete file
            $fileDeleted = JFile::delete($imagePath);
        }   
    }
    
    function saveLogo($files, $data)
    {   
        $uploadFile = JRequest::getVar('logo', null, 'FILES', 'ARRAY');
        $uploadImage = JRequest::getVar('image', null, 'FILES', 'ARRAY');
    
        $save = true;
        $saveImage = true;
    
        if (!is_array($uploadFile)) {
            // @todo handle no upload present
            $save = false;
        }
    
        if ($uploadFile['error'] || $uploadFile['size'] < 1) {
            // @todo handle upload error
            $save = false;
        }
    
        if (!is_uploaded_file($uploadFile['tmp_name'])) {
            // @todo handle potential malicious attack
            $save = false;
        }
    
        if (!is_array($uploadImage)) {
            // @todo handle no upload present
            $saveImage = false;
        }
    
        if ($uploadImage['error'] || $uploadImage['size'] < 1) {
            // @todo handle upload error
            $saveImage = false;
        }
    
        if (!is_uploaded_file($uploadImage['tmp_name'])) {
            // @todo handle potential malicious attack
            $saveImage = false;
        }
    
        // Prepare the temporary destination path
        //$config = & JFactory::getConfig();
        //$fileDestination = $config->getValue('config.tmp_path'). DS . JFile::getName($uploadFile['tmp_name']);
    
        // Move uploaded file
    
        if($save)
        {
            $this->deleteLogo($data['oldLogo']);
            $fileDestination = 'images/stories/members/' . $data['id'] . '-' . $uploadFile['name'];
            $uploaded = JFile::upload($uploadFile['tmp_name'], $fileDestination);
        }
    
        if($saveImage)
        {
            $this->deleteLogo($data['oldImage']);
            $fileDestination = 'images/stories/members/image/' .  $data['id'] . '-' . $uploadImage['name'];
            $uploadedImage = JFile::upload($uploadImage['tmp_name'], $fileDestination);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-22
      • 2019-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多