老师,我用uploadify插件再本地上传图片,正常上传正常展示;
把代码部署到服务器就正常上传但是页面显示不出来图片,
本地代码
<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图1:</label>
<div class="formControls col-xs-8 col-sm-9">
<input id="file_upload" type="file" multiple="true" >
<img style="display: none" id="upload_org_code_img" src="" width="150" height="150">
<span>
<input id="file_upload_image" name="image1" type="hidden" multiple="true" value="">
</span>
</div>
<script>
swf = '/static/admin/uploadify/uploadify.swf';
image_upload_url = "{:url('image/upload')}";
</script>
$("#file_upload").uploadify({
swf : swf, //定义变量
uploader : image_upload_url,//定义变量
buttonText : '图1',
fileTypeDesc : 'Image files',
fileObjName : 'file' ,//php获取
fileTypeExts : '*.gif;*.jpg;*.png;',//允许上传类型
/*file 上传文件 date 接口image_upload_url */
onUploadSuccess :function (file,date,response){
//扩展内容
if(response){
var obj = JSON.parse(date);//php传过来的json解析 图片
$('#upload_org_code_img').attr("src","/"+obj.date);//图片
$('#file_upload_image').attr("value","/"+obj.date);//value
//默认关闭 上传之后开启
$('#upload_org_code_img').show();
}
}
});
public function upload(){
$file = Request::instance()->file('file');
$info = $file->move('upload');//默认是public下创建
if($info && $info->getPathname()){
//接口api返回数据形式
$date =[
'status' =>1,
'meaagse' =>'ok',
'date' =>$info->getPathname(),
];
echo json_encode($date);exit;
}
echo json_encode(['status' => 0,'message'=>'上传失败']);
}
js报错:
Uncaught SyntaxError: Unexpected token in JSON at position 0
VM485675:1 Uncaught SyntaxError: Unexpected token in JSON at position 0
at JSON.parse ()
at SWFUpload.onUploadSuccess (image.js:16)
at SWFUpload.onUploadSuccess (jquery.uploadify.min.js:16)
at SWFUpload. (jquery.uploadify.min.js:16)
at SWFUpload.executeNextEvent (jquery.uploadify.min.js:16)
at jquery.uploadify.min.js:16