繁体   English   中英

Joomla自定义用户扩展

[英]Joomla custom user extension

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

是否有标准的Joomla图片上传功能?

谢谢

我的代码是这样的:(还有一些我无法在此处粘贴所有内容)

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);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM