Php Yii使用Ajax上传作物图像问题
嗨,我只是想用yii扩展中的navajcrop上传图像。它使用ajax调用上传图像。我可以上传图片。但问题是无法查看上载的图像。当我查看上载的图像时,它会显示以下错误:-错误解释JPEG图像文件(不是JPEG文件:以0x75 0xab开头) 控制器代码:-Php Yii使用Ajax上传作物图像问题,php,jquery,yii,yii-extensions,Php,Jquery,Yii,Yii Extensions,嗨,我只是想用yii扩展中的navajcrop上传图像。它使用ajax调用上传图像。我可以上传图片。但问题是无法查看上载的图像。当我查看上载的图像时,它会显示以下错误:-错误解释JPEG图像文件(不是JPEG文件:以0x75 0xab开头) 控制器代码:- public function actionUpload(){ $model = new Register(); if(isset($_POST)){ $rnd = rand(0, 9999);
public function actionUpload(){
$model = new Register();
if(isset($_POST)){
$rnd = rand(0, 9999);
$img = $_POST['image'];
if($img != '/img/noimage.png' && $img != $model->image){
$img = str_replace('data:image/jpeg;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = Yii::app()->basePath . '/../themes/front/assets/img/photo/' . $rnd.'.jpg';
file_put_contents($file, $data);
}
}
}
JS代码:-
function doSomething(obj,res){ //the 'obj' is IMG tag, 'res' is base64image
$.ajax({
cache: false,
type: 'post',
//url: <?php echo Yii::app()->createUrl('site/upload');?>,
url: baseUrl+"/admin/ajax/Upload",
data: 'image='+res,
success: function(){
obj.attr('src',res);
}
});
}
函数doSomething(obj,res){//obj是IMG标记,“res”是base64image
$.ajax({
cache:false,
键入:“post”,
//网址:,
url:baseUrl+“/admin/ajax/Upload”,
数据:“图像=”+res,
成功:函数(){
对象属性('src',res);
}
});
}
查看代码:-
<?php $this->widget('ext.NavaJcrop.ImageJcrop', array(
'config' => array(
'title'=>$model->image,
'image'=>$model->image,//required, all field below are not required.
'id'=>'nava-jcrop',
//'unique'=>true,
'buttons'=>array(
'cancel'=>array(
'name'=>'Cancel',
'class'=>'button-crop',
'style'=>'margin-left: 5px;',
),
/*'edit'=>array(
'name'=>'Edit',
'class'=>'button-crop',
'style'=>'margin-left: 5px;',
),*/
'crop'=>array(
'name'=>'Crop',
'class'=>'button-crop',
'style'=>'margin-left: 5px;',
)
),
'options'=>array(
'imageWidth'=>150,
'imageHeight'=>175,
'resultStyle'=>'position: fixed;top: 400px;max-width:350px;max-height:350px;z-index: 9999;',
'resultMaxWidth'=>350,
'resultMinWidth'=>350,
),
'callBack'=> array(
'success'=>"function(obj,res){doSomething(obj,res);}",
'error'=>"function(){alert('error');}",
)
)
)); ?>
您好,我已经解决了我的问题,这是下面语法中的错误
在控制器操作中:-编辑
$img=str_replace('data:image/png;base64','','$img)
$file=Yii::app()->basePath'//主题/front/assets/img/photo/”$rnd.“.png” 您好,阿米特,您是说您可以加载图像,但您是否尝试直接打开该文件?似乎没有合适的扩展。。。