2015-01-20 4 views
0

안녕하세요 저는 yii 확장에 navajcrop을 사용하여 이미지를 업로드하려고합니다. ajax 호출을 사용하여 이미지를 업로드합니다. 이미지를 업로드 할 수 있습니다.Yii 자르기 Ajax를 사용하여 이미지 업로드 문제

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); 

     } 
    } 
} 
- :

컨트롤러 코드 (0x75 확인 0xAB로 시작하지 JPEG 파일을) 오류가 JPEG 이미지 파일을 해석 - :하지만 문제는 업로드 된 이미지가 내가 그것을 오류 아래에 표시 업로드 된 이미지를 볼 수 view.when 수 없다는 것입니다

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); 
     } 
    }); 
} 

보기 코드 : -

<?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');}", 
     ) 

    ) 
)); ?> 

하십시오 시간 이 오류를 풀기위한 엘프.

+0

안녕하세요, 이미지를로드 할 수 있지만 파일을 직접 열어 보았습니다. 그것은 적절한 확장 기능이없는 것 같습니다 ... – DiegoCoderPlus

답변

0

안녕하세요, 아래 문법의 버그였습니다. 제 질문을 해결했습니다. 컨트롤러 행동

- 편집

$ IMG 않는 str_replace = ('데이터 : 이미지/PNG;베이스 64는,' '', IMG 달러);

$ file = Yii :: app() -> basePath. '/../themes/front/assets/img/photo/'. $ rnd. '. png';