CakePHP 2.0 Miles J Uploader插件-$uploadDir覆盖错误
我试图在AttachmentsController中动态设置$uploadDir,但每当我尝试使用时:CakePHP 2.0 Miles J Uploader插件-$uploadDir覆盖错误,cakephp,plugins,cakephp-2.0,file-upload,uploader,Cakephp,Plugins,Cakephp 2.0,File Upload,Uploader,我试图在AttachmentsController中动态设置$uploadDir,但每当我尝试使用时: $this->Uploader = new Uploader( array('uploadDir' => "/files/uploads/clients/".$id."/" ) ); uploadDir变量默认为Plugin/Uploader/Vendor/Uploader.php文件中的变量 我已经尝试从$actAs数组和AttachmentBehavior.php中的$\
$this->Uploader = new Uploader( array('uploadDir' => "/files/uploads/clients/".$id."/" ) );
uploadDir变量默认为Plugin/Uploader/Vendor/Uploader.php文件中的变量
我已经尝试从$actAs数组和AttachmentBehavior.php中的$\u默认值中删除'uploadDir'变量声明,但没有成功
我只使用CakePHP几个星期了,我似乎不知道如何让它工作
当我打印时($this->Uploader);
uploadDir变量设置正确,但当我检查上载目录时,它会保存到Uploader.php类中设置的默认位置
代码如下:
AttachmentsController.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");
}
}
}
}
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
)
)
)
);
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' => ''
)
);
}
Attachment.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");
}
}
}
}
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
)
)
)
);
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' => ''
)
);
}
Uploader.php类
这个变量总是覆盖我的设置,我不知道如何使它配合
/**
* Destination upload directory within $baseDir.
*
* @access public
* @var string
*/
public $uploadDir = 'files/uploads/2012/';
AttachmentBehavior.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");
}
}
}
}
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
)
)
)
);
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类中的文件夹。必须更改所有这些文件夹,以找出控制内容的文件。
我希望插件的文档中有更多的例子,并对如何进行初始设置有更清晰的解释 那为什么不呢
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;
您可以随时向提交文档和bug,为什么不呢
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;
您可以随时将文档和bug提交给