function saveImage($gid, $imgThumbnail, $imgDefault, $aImgFile, $imgUdf = 'false', &$newThumbnail) { foreach ($aImgFile as $k => $v) { if (!$v) { unset($aImgFile[$k]); } } if (!isset($aImgFile[0])) { $aImgFile = array(0); } $this->clean($gid, $aImgFile); $this->_gen_all_size('gimage_id in (' . implode(',', $aImgFile) . ')', $gid); if (!($row = $this->db->selectrow('select gimage_id,small,thumbnail,big from sdb_gimages where gimage_id=' . intval($imgDefault)))) { $row = $this->db->selectrow('select gimage_id,small,thumbnail,big from sdb_gimages where goods_id=' . intval($gid)); $imgDefault = $row['gimage_id']; } if (substr($newThumbnail, 0, 4) == 'http') { $row['thumbnail'] = $newThumbnail; } $data = array('thumbnail_pic' => $row['thumbnail'], 'small_pic' => $row['small'], 'big_pic' => $row['big'], 'image_default' => $imgDefault, 'goods_id' => $gid, 'udfimg' => $imgUdf); $old_img = $this->db->selectrow('select udfimg,thumbnail_pic from sdb_goods where goods_id=' . intval($gid)); if ($imgUdf == 'true' && $newThumbnail['goods_thumbnail_pic'] && substr($newThumbnail, 0, 4) != 'http') { //????? $data['thumbnail_pic'] = parent::save_upload($newThumbnail['goods_thumbnail_pic'], 'goods', substr(md5(implode(',', microtime() . rand(0, time()))), 0, 16) . ext_name($newThumbnail['goods_thumbnail_pic']['name'])); if ($this->elmar_storage) { if ($w = strpos($old_img['thumbnail_pic'], '|img_id:')) { $old_img_id = substr($old_img['thumbnail_pic'], $w + strlen('|img_id:')); if ($old_img_id) { $file = BASE_DIR . '/' . substr($data['thumbnail_pic'], 0, strpos($data['thumbnail_pic'], '|')); if (!$this->elmar_storage->update($old_img_id, $file, 'thumb')) { trigger_error("更新图库信息失败", E_USER_WARNING); } $elmer_t_url = explode('|', $old_img['thumbnail_pic']); $data['thumbnail_pic'] .= '|' . $elmer_t_url[3] . '|img_id:' . $old_img_id; } } } if ($old_img['udfimg'] == 'true') { $this->remove($old_img['thumbnail_pic']); } } else { //??? if ($imgUdf == 'false' && $old_img['udfimg'] == 'true') { $this->remove($old_img['thumbnail_pic']); } if ($imgUdf == 'true' && $old_img['udfimg'] == 'true') { unset($data['thumbnail_pic']); } } return $this->toUpdateImages($data); }
function saveImage($gid, $imgThumbnail, $imgDefault, $aImgFile, $imgUdf = 'false', &$newThumbnail) { foreach ($aImgFile as $k => $v) { if (!$v) { unset($aImgFile[$k]); } } if (!isset($aImgFile[0])) { $aImgFile = array(0); } $this->clean($gid, $aImgFile); $this->_gen_all_size('gimage_id in (' . implode(',', $aImgFile) . ')', $gid); if (!($row = $this->db->selectrow('select gimage_id,small,thumbnail,big from sdb_gimages where gimage_id=' . intval($imgDefault)))) { $row = $this->db->selectrow('select gimage_id,small,thumbnail,big from sdb_gimages where goods_id=' . intval($gid)); $imgDefault = $row['gimage_id']; } if (substr($newThumbnail, 0, 4) == 'http') { $row['thumbnail'] = $newThumbnail; } $data = array('thumbnail_pic' => $row['thumbnail'], 'small_pic' => $row['small'], 'big_pic' => $row['big'], 'image_default' => $imgDefault, 'goods_id' => $gid, 'udfimg' => $imgUdf); $old_img = $this->db->selectrow('select udfimg,thumbnail_pic from sdb_goods where goods_id=' . intval($gid)); if ($imgUdf == 'true' && $newThumbnail['goods_thumbnail_pic'] && substr($newThumbnail, 0, 4) != 'http') { if ($newThumbnail['goods_thumbnail_pic']['img_source'] == 'local') { $data['thumbnail_pic'] = parent::save($newThumbnail['goods_thumbnail_pic']['name'], 'goods', substr(md5(implode(',', microtime() . rand(0, time()))), 0, 16) . ext_name($newThumbnail['goods_thumbnail_pic']['name'])); } else { $data['thumbnail_pic'] = parent::save_upload($newThumbnail['goods_thumbnail_pic'], 'goods', substr(md5(implode(',', microtime() . rand(0, time()))), 0, 16) . ext_name($newThumbnail['goods_thumbnail_pic']['name'])); } if ($old_img['udfimg'] == 'true') { $old_gimg = $this->db->selectrow('select thumbnail from sdb_gimages where goods_id=' . intval($gid)); if ($old_gimg['thumbnail'] != $old_img['thumbnail_pic']) { $this->remove($old_img['thumbnail_pic']); } } } else { //没有上传缩略图 if ($imgUdf == 'false' && $old_img['udfimg'] == 'true') { $this->remove($old_img['thumbnail_pic']); } if ($imgUdf == 'true' && $old_img['udfimg'] == 'true') { unset($data['thumbnail_pic']); } } return $this->toUpdateImages($data); }