1

$uploadDir を AttachmentsController で動的に設定しようとしていますが、使用しようとするたびに:

$this->Uploader = new Uploader( array('uploadDir'  =>  "/files/uploads/clients/".$id."/" ) );

uploadDir 変数のデフォルトは、Plugin/Uploader/Vendor/Uploader.php ファイル内のものです。

$actAs 配列と、AttachmentBehavior.php の $_defaults から 'uploadDir' 変数宣言を削除しようとしましたが、うまくいきませんでした。

私は CakePHP を数週間しか使っていませんが、これを機能させる方法がわかりません。

私が print_r($this->Uploader); uploadDir 変数は適切に設定されていますが、アップロード ディレクトリを確認すると、Uploader.php クラスに設定されているデフォルトの場所に保存されます。

以下のコード:

添付ファイルController.php

App::import('Vendor', 'Uploader.Uploader');

class AttachmentsController extends AppController {        

public $helpers = array("Html", "Form", "Session");
public $uses = array("Attachment");

public function index()
{        
    $docs = $this->Attachment->findAllByClientIdAndUserId( $this->Session->read("Client.id"), AuthComponent::user('id') );
    $this->set("page",10);
    $this->set("docs",$docs);
}

public function upload()
{

    if( $this->request->is('post'))
    {
        $id = $this->Session->read("Client.id");
        unset($this->Uploader);
        $this->Uploader = new Uploader( array('uploadDir' => '/files/uploads/wizno/' ) );
        $this->Uploader->setup( array('uploadDir' => '/files/uploads/wizno/' ) );
        //print_r($this->Uploader);            
        //exit;

          if(!empty($this->data)){
               if($this->Attachment->save($this->data))
               {
                    $this->redirect("/attachments");
               }
          }
    }

}

}

添付ファイル.php

class Attachment extends AppModel {
public $name = "Attachment";
public $belongsTo = array("Client","User");
public $useTable = "uploads";

public $virtualFields = array(
'created'   =>  'DATE_FORMAT(Attachment.created, "%m/%d/%Y")',
'modified'  =>  'DATE_FORMAT(Attachment.modified, "%m/%d/%Y")'
);

public $actsAs = array(     
    'Uploader.Attachment' => array(
        'file' => array(
            'name'      =>  '',
            'uploadDir' =>  "/files/uploads/clients/WTF/500",
            'dbColumn' => 'path',
            'maxNameLength' => 50,
            'overwrite' => true,
            'stopSave' => true,

            'metaColumns' => array(
                'size' => 'filesize',   // The size value will be saved to the filesize column
                'type' => 'type'        // And the same for the mimetype
            )
                    )
    )
);

}

Uploader.php クラス この変数は常に私の設定を上書きしますが、連携させる方法がわかりません。

/**
 * Destination upload directory within $baseDir.
 *
 * @access public
 * @var string
 */
public $uploadDir = 'files/uploads/2012/';

AttachmentBehavior.php

protected $_defaults = array(
    'name' => '',
    'baseDir' => '',
    'uploadDir' => '/files/100/',       
    'dbColumn' => 'path',       
    'defaultPath' => '',
    'maxNameLength' => null,
    'overwrite' => false,           // Overwrite a file with the same name if it exists
    'stopSave' => true,             // Stop model save() on form upload error
    'allowEmpty' => true,           // Allow an empty file upload to continue
    'saveAsFilename' => true,       // If true, will only save the filename and not relative path               
    'metaColumns' => array(
        'ext' => '',
        'type' => '',
        'size' => '',
        'group' => '',
        'width' => '',
        'height' => '',
        'filesize' => ''
    )
);

'uploadDir' がさまざまなファイルの異なるフォルダーに設定されているにもかかわらず、デフォルトで Uploader.php クラスのフォルダーに設定されます。これらすべてのフォルダーを変更して、どのファイルが物事を制御しているかを確認する必要がありました。

プラグインのドキュメントにもっと多くの例があり、初期設定の方法についてより明確な説明があればいいのにと思います。

4

1 に答える 1

1

では、なぜでしょうか

CakePlugin::load('Uploader');       
App::import('Vendor', 'Uploader.Uploader');

$this->Uploader = new Uploader(array('tempDir' => TMP,'uploadDir'=> DS . 'custom_dir' . DS));

//OR

$this->Uploader->uploadDir = DS . 'custom_dir' . DS;

ドキュメントとバグはいつでもMiles の github リポジトリに送信できます

于 2012-04-27T14:14:43.663 に答える