首页 > php+bootstrap fileinput去上传图片,返回失败,求助!

php+bootstrap fileinput去上传图片,返回失败,求助!

正常提交的话,应该返回这个,如图
而下面的代码返回

<admintpl file="header" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml&...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>

  
    <!--<input id="input-2" name="input2" type="file" class="file-loading" multiple data-preview-file-type="any">-->
      <input id="input-2" name="input2" type="file" class="file-loading" >
    <script type="text/javascript">
    
    var ctrlName = 'input-2';
    var control = $('#' + ctrlName); 

    
     control.fileinput({
        uploadUrl:"{:U('profile/upload')}",
        showCaption: false,
        showCancel:false,
        showUploadedThumbs:false,
        showClose:false,
        autoReplace:true,
        maxFileCount:5,
        overwriteInitial:true,
        showUploadedThumbs:false,
        language:'zh',
        initialPreview:"<img src='/back_t.jpg' class='file-preview-image' />",
        initialPreviewCount:1,
        initialPreviewShowDelete:false,
        layoutTemplates:{
             actions: '<div class="file-actions">\n' +
    '    <div class="file-footer-buttons">\n' +
    '    </div>\n' +
    '    <div class="file-upload-indicator" tabindex="-1" title="{indicatorTitle}">{indicator}</div>\n' +
    '    <div class="clearfix"></div>\n' +
    '</div>'
        }
    }).on('fileuploaded', function(event, data, previewId, index){ 
                  var str = JSON.stringify(data);  

alert(str);

    });
    
    
    </script>

</body>
</html>
namespace PartnerController;
use CommonControllerMemberbaseController;
class ProfileController extends MemberbaseController {

    public function upload(){  


    if ($_FILES['input2']["type"] == "image/png") {
    echo "{\"code\":0, \"message\":\"upload success!\"}";
} else {
    echo "{\"code\":-1, \"error\":\"Invalid file format\"}";
}

}
}

【热门文章】
【热门文章】