2012-10-16 1 views
3

이 플러그인을 사용하고 있습니다 : MileJ CakePHP Uploader 정말 잘 작동하지만 컨트롤러를 통해 작동하도록 할 수는 있습니다. 작동 할 필요가있는 모델의 동작이 아니라 컨트롤러를 사용할 수 있습니다. 기능을 사용하여 Amazon s3에 파일을 전달합니다.CakePHP 업 로더 플러그인 - 작동 설정

내 코드는 다음과 같습니다. 어디서 잘못 볼 수 있습니까? 현재 데이터베이스 레코드가 생성되지만 다른 필드 (캡션, card_id, user_id)에 대해서만 파일과 관련이 없습니다. 파일은 업로드되지 않습니다.

모델 : DataFile.php

public $actsAs = array(
    'Uploader.FileValidation' => array(
     'file1' => array(
      'required' => true 
     ), 
     'file2' => array(
      'required' => false 
     ), 
     'file3' => array(
      'required' => true 
     ) 
    ), 
    'Uploader.Attachment' => array(
     'file' => array(
      'name' => '', 
      'uploadDir' => 'files/data_files/', 
      'dbColumn' => 'path', 
      'maxNameLength' => 30, 
      'overwrite' => true, 
      'stopSave' => false, 
      's3'  => array(
           'accessKey' => 'MYACCESSKEY', 
           'secretKey' => 'MYSECRETKEY', 
           'ssl' => true, 
           'bucket' => 'testfilespath', 
           'path' => '/' 
          ),     // Array of Amazon S3 settings    
      'metaColumns' => array(
        'ext' => 'extension', 
        'size' => 'bytesize', 
        'group' => 'group', 
        'width' => 'width', 
        'height' => 'height', 
        'filesize' => 'filesize' 
      ) 
     ) 
    ) 
); 

컨트롤러 : DataFileController.php

// ADD BY BEHAVIOUR NEW FILE(S) - NOT WORKING 
// ----------------------------------------------------------> 
function add_behavior() 
{ 
    if (!empty($this->request->data)) 
    { 

     if ($this->DataFile->save($this->request->data)) 
     { 
      debug($this->request->data); 

      $this->Session->setFlash(__('The File has been uploaded'); 
      $this->redirect(array('action' => 'index')); 
     } 
     else 
     { 
      $this->Session->setFlash(__('The DataFile could not be saved. Please, try again.')); 
     } 
    } 
} 

보기 : add_behavior.ctp

<?php echo $this->Form->create('DataFile', array('type' => 'file')); ?> 
    <?php 
    echo $this->Form->input('user_id', array('value' => $this->Session->read("Auth.User.id"), 'type' => 'text')); 
    echo $this->Form->input('card_id', array('value' => '1', 'type' => 'text')); 
    echo $this->Form->input('caption', array('label' => 'File Title')); 
    echo $this->Form->input('file1', array('type' => 'file', 'label' => 'File')); 
    ?> 
    <?php echo $this->Form->end(__('Upload'));?> 

답변

2
Uploader.Attachment => array(
     'file1' => array(...), 
     'file2' => array(...), 
     'file3' => array(...), 
); 

동작을 사용할 때는 Uploader.Attachment 배열 내에 파일 필드의 이름을 지정해야합니다.

귀하의 양식 필드는 file1이며, 현재 동작은 file입니다.

+0

도움을 주셔서 감사합니다. 그런 바보 같은 실수를 저 지르십시오. – sluggerdog

+0

내가이 플러그인을 처음 사용하기 시작할 때도 같은 실수를 저질렀습니다. 제 개인적인 견해로는 문서가 약간 분명한 부분이 있다고 생각합니다. 그래도 좋은 플러그인입니다. – Ross