上传图片后看不到图片

时间:2019-05-28 17:42:25

标签: php mysql json w2ui

我试图将图片保存在目录中,保存后我想看。 它不起作用。

我设法将图像保存在所需的文件夹中,并设法在CSS中植入代码,并编写了处理该图像的函数,但看不到图片

function go_insert_user_group()
{

    $_USERGROUP = $this->loadModel('UserGroupModel');   

    $name = 'icon-developer';
    if(isset($_POST['record']['icon'][0]))
    {
        $content = $_POST['record']['icon'][0]['content'];
        $name = $_POST['record']['icon'][0]['name'];
        $name = str_replace(' ', '_', $name);
        $class = str_replace('.', '_', $name);
        file_put_contents(ROOT_STATIC_DIR.'/css/icons/'.$name, base64_decode($content));
        $css = "\n.icon-".$class."{\nbackground:url('icons/".$name."') no-repeat center center;\n}";
        $myfile = file_put_contents(ROOT_STATIC_DIR.'/css/icon.css', $css.PHP_EOL , FILE_APPEND | LOCK_EX);
    }

    $array = array(
        "id" => null,
        "groupcode" => $_POST['record']['groupcode'],
        "usergroup" => $_POST['record']['usergroup'],
        "badge" => $_POST['record']['badge'],
        "icon" => 'icon-'.$class
    );

    $_USERGROUP->addUserGroup($array);

    die();
}

function go_edit_user_group()
{

    $_USERGROUP = $this->loadModel('UserGroupModel');

    $name = 'icon-developer';
    if(isset($_POST['record']['icon'][0])){
        $content = $_POST['record']['icon'][0]['content'];
        $name = $_POST['record']['icon'][0]['name'];
        $name = str_replace(' ', '_', $name);
        $class = str_replace('.', '_', $name);
        file_put_contents(ROOT_STATIC_DIR.'/css/icons/'.$name, base64_decode($content));
        $css = "\n.icon-".$class."{background:url('icons/".$name."') no-repeat center center;}";
        $myfile = file_put_contents(ROOT_STATIC_DIR.'/css/icon.css', $css.PHP_EOL , FILE_APPEND | LOCK_EX);
    }

    $array = array(
        "id" => $_POST['record']['id'],
        "groupcode" => $_POST['record']['groupcode'],
        "usergroup" => $_POST['record']['usergroup'],
        "badge" => $_POST['record']['badge'],
        "icon" => 'icon-'.$class
    );

    $_USERGROUP->saveUserGroup($array);

    die();
}

.icon-box_png{ background:url('icons/box.png') no-repeat center center; }

function addUserGroup(){

    if (!w2ui.new_user_group_form) {
        $('#FORM_ADD_PROJECT').w2form({
            name: 'new_user_group_form',
            style: 'border: 0px; background-color: transparent;',
            formHTML: $('#FORM_ADD_PROJECT').html() ,
            url: '<?php echo BASE_URL; ?>usergroup/go_insert_user_group',
            fields: [
                { 
                    name     : 'groupcode',      
                    type     : 'text',       
                    options  : {},     
                    required : true,         
                    html     : {      
                        attr    : 'style="font-size:14px;width:150px"',       
                        caption : 'Group code' 
                    } 
                },
                { 
                    name     : 'usergroup',      
                    type     : 'text',       
                    options  : {},     
                    required : true,         
                    html     : {      
                        attr    : 'style="font-size:14px;width:150px"',       
                        caption : 'Group name' 
                    } 
                },
                { 
                    name     : 'badge',      
                    type     : 'text',       
                    options  : {},     
                    required : true,         
                    html     : {      
                        attr    : 'style="font-size:14px;width:150px"',       
                        caption : 'Badge' 
                    } 
                },
                { 
                    name     : 'icon',      
                    type     : 'file',       
                    options  : {
                                max  : 1,
                                onAdd: (event) => {
                                var name = event.file.name;
                                if(name.endsWith(".jpg") || name.endsWith(".bmp") || name.endsWith(".png") || name.endsWith(".gif") ){} else {
                                alert('File type should be jpg,bmp,png or gif.');
                                event.preventDefault()
                            }
                        }
                    },     
                    required : true,         
                    html     : {      
                        attr    : 'style="font-size:14px;width:250px"',       
                        caption : 'Icon',
                        text: ' '                       
                    } 
                },
            ],
            record: {
                status: 1
            },
            actions: {
                "Save": function () { 
                    if(this.validate()){
                        this.save();                            
                    }
                },
                "Reset": function () { this.clear(); },
            },
            onSave: function(event) {
                w2popup.close();
                showMessage('User group successfully added.','success') ;
                w2ui['user_group_grid'].reload();
            } 
        });
    }
    $().w2popup('open', {
        title   : 'New user group',
        body    : '<div id="form" style="width: 100%; height: 100%;"></div>',
        style   : 'padding: 15px 0px 0px 0px',
        width   : 700,
        height  : 280, 
        modal     : true,
        showMax : false,img: 'icon-add',
        onToggle: function (event) {
            $(w2ui.new_user_group_form.box).hide();
            event.onComplete = function () {
                $(w2ui.new_user_group_form.box).show();
                w2ui.new_user_group_form.resize();
            }
        },
        onOpen: function (event) {
            event.onComplete = function () {
                $('#w2ui-popup #form').w2render('new_user_group_form');
            }
        }
    });

0 个答案:

没有答案