nim*_*rod 6 php cakephp image-uploading cakephp-3.0
我正在使用cakephp-upload插件,我设法将图像上传到我的服务器:
WorkersTable:
public function initialize(array $config)
{
parent::initialize($config);
$this->table('workers');
$this->displayField('id');
$this->primaryKey('id');
$this->addBehavior('Josegonzalez/Upload.Upload', [
'avatar' => [
'fields' => [
'dir' => 'photo_dir'
]
]
]);
}
Run Code Online (Sandbox Code Playgroud)
view.ctp:
echo $this->Form->create($newWorker, ['type' => 'file']);
echo $this->Form->input('avatar', ['type' => 'file']);
echo $this->Form->input('photo_dir', ['type' => 'hidden']);
Run Code Online (Sandbox Code Playgroud)
现在上传了头像图像,但它们没有放入photo_dir子目录中.
我错过了什么?它在我的CakePHP 2.8.x应用程序中没有任何问题.
插件的作者在这里。
该fields.dir
属性没有说明子目录应该是什么。它是对数据库表中的列的引用,我们应该在其中保存director
文件的位置。
如果您想更改磁盘上保存文件的位置,则应该使用该path
选项。这是我使用子目录的示例photo_dir
:
$this->addBehavior('Josegonzalez/Upload.Upload', [
'avatar' => [
'path' => 'webroot{DS}files{DS}{model}{DS}{field}{DS}photo_dir{DS}'
]
]);
Run Code Online (Sandbox Code Playgroud)
path
该选项的默认值为webroot{DS}files{DS}{model}{DS}{field}{DS}
。