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\"}";
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论