TP5 업로드 이미지 리셋

5235 단어
html
<div class="img_box">
   <img src="" id="scimg" onclick="upimg()">
   <input type="file" class="noshow" id="uploadimg">
   <input type="hidden" name="headimg" id="headimg" value="1">
div>

js
    /* */
    function upimg(){
        $("#uploadimg").click();
    }

    /* */
    /* */
    $("#uploadimg").change(function(e) {
        var imgBox = e.target;
        var file = imgBox.files[0];
        var form=new FormData();
        form.append('file',file);
        $.ajax({
            url:"",
            data:form,
            type:"post",
            contentType: false,// jQuery Content-Type 
            processData: false,// jQuery 
            success:function(data){
                console.log(data);
                $("#scimg").attr('src',data);
                $("#headimg").val(data);
            }
        })
    });

php
    /* */
    public function upload(){
        //    001.jpg
        $file = request()->file('file');
        //  /uploads/  
        $info = $file->move( './upload');
        if($info){
            $getSaveName=str_replace("\\","/",$info->getSaveName());
            $path='/upload/'.$getSaveName;
            echo $path;
        }
    }

좋은 웹페이지 즐겨찾기