Kohana ORM和文件上传问题...在没有图像时将记录徽标设置为等于记录徽标

发布于 2024-11-25 10:19:43 字数 439 浏览 1 评论 0原文

这会导致此错误...

操作数应包含 1 列 [ UPDATE record SET logo = ('', '', '', 4, 0) WHERE id = '0']

if ($_FILES['logo']['name'] == '') {
    $record->logo = $record->logo;
}
else{
    // INSERTION WORKS FINE
}

我也在使用 Formo 模块,如果这有影响的话...

有没有办法直接踢出完全将徽标从插入脚本中删除等等...因为 $record->logo = $record->logo 会导致失败?

This causes this error...

Operand should contain 1 column(s) [ UPDATE record SET logo = ('',
'', '', 4, 0) WHERE id = '0' ]

if ($_FILES['logo']['name'] == '') {
    $record->logo = $record->logo;
}
else{
    // INSERTION WORKS FINE
}

I'm also using the Formo module if that makes a difference...

Is there a way to just kick-out the logo out of the insertion script altogether or such... since $record->logo = $record->logo causes a fail?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青瓷清茶倾城歌 2024-12-02 10:19:43
$record->logo = $record->logo;

如果未设置 $record->logo 将导致错误。您至少必须说:

$record->logo = '';

但最好的办法是使用 Validation::factory($_FILES)->check()

if ( $logo->check() ) {
  // do your insert here
}

这只是我上次管理此内容时的一个片段:

    $logo = Validation::factory($_FILES);
    $logo->rule('logo', 'Upload::not_empty')->rule('logo', 'Upload::type', array(':value', array('jpg', 'png', 'gif')));
    if ( $logo->check() ) {
      $logo = Upload::save($_FILES['logo'], NULL, 'assets/uploads/logo');
      $image = ORM::factory('image')->where('id', '=', $id)->where('type', '=', 'logo')->find();
      $path = explode('/', $logo);
      $path = end($path);
      $image->path = 'assets/uploads/logo/' . $path;
      $image->playlist_id = $id;
      $image->type = 'logo';
      $image->save();
    }
$record->logo = $record->logo;

Would cause an error if $record->logo is not set.. You would have to atleast say:

$record->logo = '';

but the best thing to do would be to use Validation::factory($_FILES)->check()

if ( $logo->check() ) {
  // do your insert here
}

This is just a snippet from when i last managed this:

    $logo = Validation::factory($_FILES);
    $logo->rule('logo', 'Upload::not_empty')->rule('logo', 'Upload::type', array(':value', array('jpg', 'png', 'gif')));
    if ( $logo->check() ) {
      $logo = Upload::save($_FILES['logo'], NULL, 'assets/uploads/logo');
      $image = ORM::factory('image')->where('id', '=', $id)->where('type', '=', 'logo')->find();
      $path = explode('/', $logo);
      $path = end($path);
      $image->path = 'assets/uploads/logo/' . $path;
      $image->playlist_id = $id;
      $image->type = 'logo';
      $image->save();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文