开发者

Kohana ORM and file upload issue... setting record logo to equal record logo when there is no image

开发者 https://www.devze.com 2023-03-21 14:04 出处:网络
This 开发者_Go百科causes this error... Operand should contain 1 column(s) [ UPDATE record SET logo = (\'\',

This 开发者_Go百科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?


$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();
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号