【发布时间】:2014-05-14 08:45:04
【问题描述】:
我已经为 cakephp 安装了上传插件。 我一直在试图弄清楚如何将缩略图路径或缩略图名称存储在我的名为 Portfolio 的表中名为 image_thumb 的字段中。我想以与存储原始图像名称相同的方式存储它。图像的目录选项在那里,但缩略图目录没有这样的东西。
我使用上传插件的模型代码是这样的:
public $actsAs = array(
'Upload.Upload' => array(
'image' => array(
'fields' => array(
'dir' => 'image'
),
'thumbnailSizes' => array(
'small' => '640x480',
),
'thumbnailName' => '{filename}_{size}_{geometry}',
'thumbnailPath' => '{ROOT}webroot{DS}img{DS}{model}{DS}Thumbnails{DS}'
)
)
);
控制器,添加功能,我假设插件发生的地方(虽然我在这里没有改变任何东西, 这是烘焙的代码)
public function admin_add() {
$this->layout='admin';
if ($this->request->is('post')) {
$this->Portfolio->create();
if ($this->Portfolio->save($this->request->data)) {
$this->Session->setFlash(__('The portfolio has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The portfolio could not be saved. Please, try again.'));
}
}
}
当图片路径上传到数据库时,图片本身和缩略图保存在我的应用程序的指定目录中。但我想将缩略图的路径保存在数据库中,以便在我的视图中使用它。
非常感谢您的帮助,因为我对 cakephp 还很陌生,我必须在很短的时间内弄清楚。 谢谢。
【问题讨论】:
-
您将此目录发送到数据库的控制器代码在哪里?
-
使用 'dir'=>'image_thumb' 因为它是您的字段名称。
-
我已经用控制器更新了代码。但 dir 用于原始图像。缩略图呢?我有一个图像字段,我在那里保存图像名称。但是 image_thumb 我想把拇指的名字保存在那里
-
您的数据库字段名称是 image_thumb ?如果是,则您提供了错误的目录来保存路径。
标签: image cakephp plugins model upload