【问题标题】:Cake PHP Upload plugin - How to store the thumbnail path in the databaseCake PHP Upload plugin - 如何在数据库中存储缩略图路径
【发布时间】: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


【解决方案1】:

你可能会在这里出错,应该是

'fields' => array(
                'dir' => 'image_thumb'         //table field name
            ),

【讨论】:

  • 我的数据库中有 image 和 image_thumb 作为两个单独的字段。当我使用 dir=>image 时,它​​会将我的图像名称保存在数据库的图像字段中。此外,它还会创建一个缩略图,为其命名,并将其放入指定的文件夹中。但我想将缩略图名称保存在我的 image_thumb 字段中,以便我可以在视图中使用它!
猜你喜欢
  • 2018-04-10
  • 1970-01-01
  • 2013-04-03
  • 2015-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
相关资源
最近更新 更多