2014-10-30 4 views
0

아약스없이 cakephp 이미지 업로드가 정상적으로 작동합니다. 아약스 사용 후 데이터는 이미지 디렉토리없이 삽입됩니다. 여기 cakephp-2.4 : jshelper 아약스 제출 후 이미지 디렉토리 전송 안 함

은 JS 제출 버튼

<?php echo $this->Js->submit('Submit',array(
     'before'=>$this->Js->get('#sending')->effect('fadeIn',array('speed' => 'slow')), 
     'success'=>$this->Js->get('#sending')->effect('fadeOut',array('speed' => 'slow')), 
     'class' => 'btn btn-danger', 
     'style'=>'width:45%;margin-top:1%;height:30px;') 
     ); 
    ?> 
보기 파일 필드 여기

echo $this->Form->input('product_image',array('type' => 'file','label' => false,)); 

내 모델 여기에 코드

public function processCoverUpload($check = array()) { 
      if (!is_uploaded_file($check['product_image']['tmp_name'])) { 
       return FALSE; 
      } 
      if (!move_uploaded_file($check['product_image']['tmp_name'], WWW_ROOT . 'img' . DS . 'uploads' . DS . $check['product_image']['name'])) { 
       return FALSE; 
      } 
      $this->data[$this->alias]['product_image'] = 'uploads/'. $check['product_image']['name']; 
      return TRUE; 
     } 

컨트롤러 여기

if ($this->request->is('post')) { 
      $this->MadProduct->create(); 

      $data = $this->request->data['MadProduct']; 
         if (!$data['product_image']['name']) { 
          unset($data['product_image']); 
         } 
      if ($this->MadProduct->save($data)) { 
       $this->Session->setFlash(__('The mad product has been saved.')); 
       return $this->redirect(array('action' => 'index')); 
      } else { 
       $this->Session->setFlash(__('The mad product could not be saved. Please, try again.')); 
      } 
     } 

이미지 디렉토리를 jshelper로 보내려면 어떻게해야합니까?

답변

0

JS 도우미는 "새로운"XHR2 기능을 사용해야하는 파일 업로드를 지원하지 않습니다.

JS 도우미/엔진을 확장하고 파일 지원을 추가 할 수 있지만 JS 도우미가 deprecated이므로 어쨌든 JavaScript를 직접 사용하는 것이 좋습니다. AJAX를 통해 파일을 업로드하는 방법을 보여주는 예제가 충분합니다.

How can I upload files asynchronously?