/** * 保存某商品的相册图片 * @param int $goods_id * @param array $image_files * @param array $image_descs * @return void */ function handle_gallery_image($goods_id, $image_files, $image_descs, $image_urls) { /* 是否处理缩略图 */ $proc_thumb = isset($GLOBALS['shop_id']) && $GLOBALS['shop_id'] > 0 ? false : true; foreach ($image_descs as $key => $img_desc) { /* 是否成功上传 */ $flag = false; if (isset($image_files['error'])) { if ($image_files['error'][$key] == 0) { $flag = true; } } else { if ($image_files['tmp_name'][$key] != 'none') { $flag = true; } } if ($flag) { // 生成缩略图 if ($proc_thumb) { $thumb_url = $GLOBALS['image']->make_thumb($image_files['tmp_name'][$key], $GLOBALS['_CFG']['thumb_width'], $GLOBALS['_CFG']['thumb_height']); $thumb_url = is_string($thumb_url) ? $thumb_url : ''; } $upload = array('name' => $image_files['name'][$key], 'type' => $image_files['type'][$key], 'tmp_name' => $image_files['tmp_name'][$key], 'size' => $image_files['size'][$key]); if (isset($image_files['error'])) { $upload['error'] = $image_files['error'][$key]; } $img_original = $GLOBALS['image']->upload_image($upload); if ($img_original === false) { sys_msg($GLOBALS['image']->error_msg(), 1, array(), false); } $img_url = $img_original; if (!$proc_thumb) { $thumb_url = $img_original; } // 如果服务器支持GD 则添加水印 if ($proc_thumb && gd_version() > 0) { $pos = strpos(basename($img_original), '.'); $newname = dirname($img_original) . '/' . $GLOBALS['image']->random_filename() . substr(basename($img_original), $pos); copy('../' . $img_original, '../' . $newname); $img_url = $newname; $GLOBALS['image']->add_watermark('../' . $img_url, '', $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']); } /* 重新格式化图片名称 */ $img_original = reformat_image_name('gallery', $goods_id, $img_original, 'source'); $img_url = reformat_image_name('gallery', $goods_id, $img_url, 'goods'); $thumb_url = reformat_image_name('gallery_thumb', $goods_id, $thumb_url, 'thumb'); $sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original) " . "VALUES ('{$goods_id}', '{$img_url}', '{$img_desc}', '{$thumb_url}', '{$img_original}')"; $GLOBALS['db']->query($sql); /* 不保留商品原图的时候删除原图 */ if ($proc_thumb && !$GLOBALS['_CFG']['retain_original_img'] && !empty($img_original)) { $GLOBALS['db']->query("UPDATE " . $GLOBALS['ecs']->table('goods_gallery') . " SET img_original='' WHERE `goods_id`='{$goods_id}'"); @unlink('../' . $img_original); } } elseif (!empty($image_urls[$key]) && $image_urls[$key] != $GLOBALS['_LANG']['img_file'] && $image_urls[$key] != 'http://' && copy(trim($image_urls[$key]), ROOT_PATH . 'temp/' . basename($image_urls[$key]))) { $image_url = trim($image_urls[$key]); //定义原图路径 $down_img = ROOT_PATH . 'temp/' . basename($image_url); // 生成缩略图 if ($proc_thumb) { $thumb_url = $GLOBALS['image']->make_thumb($down_img, $GLOBALS['_CFG']['thumb_width'], $GLOBALS['_CFG']['thumb_height']); $thumb_url = is_string($thumb_url) ? $thumb_url : ''; $thumb_url = reformat_image_name('gallery_thumb', $goods_id, $thumb_url, 'thumb'); } if (!$proc_thumb) { $thumb_url = htmlspecialchars($image_url); } /* 重新格式化图片名称 */ $img_url = $img_original = htmlspecialchars($image_url); $sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original) " . "VALUES ('{$goods_id}', '{$img_url}', '{$img_desc}', '{$thumb_url}', '{$img_original}')"; $GLOBALS['db']->query($sql); @unlink($down_img); } } }
$db->query("UPDATE " . $ecs->table('goods') . " SET original_img = '{$original_img}' WHERE goods_id='{$goods_id}'"); } if ($goods_thumb !== false) { $db->query("UPDATE " . $ecs->table('goods') . " SET goods_thumb = '{$goods_thumb}' WHERE goods_id='{$goods_id}'"); } /* 如果有图片,把商品图片加入图片相册 */ if (isset($img)) { /* 重新格式化图片名称 */ if (empty($is_url_goods_img)) { $img = reformat_image_name('gallery', $goods_id, $img, 'source'); $gallery_img = reformat_image_name('gallery', $goods_id, $gallery_img, 'goods'); } else { $img = $url_goods_img; $gallery_img = $url_goods_img; } $gallery_thumb = reformat_image_name('gallery_thumb', $goods_id, $gallery_thumb, 'thumb'); $sql = "INSERT INTO " . $ecs->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original) " . "VALUES ('{$goods_id}', '{$gallery_img}', '', '{$gallery_thumb}', '{$img}')"; $db->query($sql); } /* 处理相册图片 */ handle_gallery_image($goods_id, $_FILES['img_url'], $_POST['img_desc'], $_POST['img_file']); /* 编辑时处理相册图片描述 */ if (!$is_insert && isset($_POST['old_img_desc'])) { foreach ($_POST['old_img_desc'] as $img_id => $img_desc) { $sql = "UPDATE " . $ecs->table('goods_gallery') . " SET img_desc = '{$img_desc}' WHERE img_id = '{$img_id}' LIMIT 1"; $db->query($sql); } } /* 不保留商品原图的时候删除原图 */ if ($proc_thumb && !$_CFG['retain_original_img'] && !empty($original_img)) { $db->query("UPDATE " . $ecs->table('goods') . " SET original_img='' WHERE `goods_id`='{$goods_id}'");
/** * 图片处理函数 * * @access public * @param integer $page * @param integer $page_size * @param integer $type * @param boolen $thumb 是否生成缩略图 * @param boolen $watermark 是否生成水印图 * @param boolen $change true 生成新图,删除旧图 false 用新图覆盖旧图 * @param boolen $silent 是否执行能忽略错误 * * @return void */ function process_image($page = 1, $page_size = 100, $type = 0, $thumb = true, $watermark = true, $change = false, $silent = true) { if ($type == 0) { $sql = "SELECT g.goods_id, g.original_img, g.goods_img, g.goods_thumb FROM " . $GLOBALS['ecs']->table('goods') . " AS g WHERE g.original_img > ''" . $GLOBALS['goods_where']; $res = $GLOBALS['db']->SelectLimit($sql, $page_size, ($page - 1) * $page_size); while ($row = $GLOBALS['db']->fetchRow($res)) { $goods_thumb = ''; $image = ''; /* 水印 */ if ($watermark) { /* 获取加水印图片的目录 */ if (empty($row['goods_img'])) { $dir = dirname(ROOT_PATH . $row['original_img']) . '/'; } else { $dir = dirname(ROOT_PATH . $row['goods_img']) . '/'; } $image = $GLOBALS['image']->make_thumb(ROOT_PATH . $row['original_img'], $GLOBALS['_CFG']['image_width'], $GLOBALS['_CFG']['image_height'], $dir); //先生成缩略图 if (!$image) { //出错返回 $msg = sprintf($GLOBALS['_LANG']['error_pos'], $row['goods_id']) . "\n" . $GLOBALS['image']->error_msg(); if ($silent) { $GLOBALS['err_msg'][] = $msg; continue; } else { make_json_error($msg); } } $image = $GLOBALS['image']->add_watermark(ROOT_PATH . $image, '', $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']); if (!$image) { //出错返回 $msg = sprintf($GLOBALS['_LANG']['error_pos'], $row['goods_id']) . "\n" . $GLOBALS['image']->error_msg(); if ($silent) { $GLOBALS['err_msg'][] = $msg; continue; } else { make_json_error($msg); } } /* 重新格式化图片名称 */ $image = reformat_image_name('goods', $row['goods_id'], $image, 'goods'); if ($change || empty($row['goods_img'])) { /* 要生成新链接的处理过程 */ if ($image != $row['goods_img']) { $sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . " SET goods_img = '{$image}' WHERE goods_id = '" . $row['goods_id'] . "'"; $GLOBALS['db']->query($sql); /* 防止原图被删除 */ if ($row['goods_img'] != $row['original_img']) { @unlink(ROOT_PATH . $row['goods_img']); } } } else { replace_image($image, $row['goods_img'], $row['goods_id'], $silent); } } /* 缩略图 */ if ($thumb) { if (empty($row['goods_thumb'])) { $dir = dirname(ROOT_PATH . $row['original_img']) . '/'; } else { $dir = dirname(ROOT_PATH . $row['goods_thumb']) . '/'; } $goods_thumb = $GLOBALS['image']->make_thumb(ROOT_PATH . $row['original_img'], $GLOBALS['_CFG']['thumb_width'], $GLOBALS['_CFG']['thumb_height'], $dir); /* 出错处理 */ if (!$goods_thumb) { $msg = sprintf($GLOBALS['_LANG']['error_pos'], $row['goods_id']) . "\n" . $GLOBALS['image']->error_msg(); if ($silent) { $GLOBALS['err_msg'][] = $msg; continue; } else { make_json_error($msg); } } /* 重新格式化图片名称 */ $goods_thumb = reformat_image_name('goods_thumb', $row['goods_id'], $goods_thumb, 'thumb'); if ($change || empty($row['goods_thumb'])) { if ($row['goods_thumb'] != $goods_thumb) { $sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . " SET goods_thumb = '{$goods_thumb}' WHERE goods_id = '" . $row['goods_id'] . "'"; $GLOBALS['db']->query($sql); /* 防止原图被删除 */ if ($row['goods_thumb'] != $row['original_img']) { @unlink(ROOT_PATH . $row['goods_thumb']); } } } else { replace_image($goods_thumb, $row['goods_thumb'], $row['goods_id'], $silent); } } } } else { /* 遍历商品相册 */ $sql = "SELECT album.goods_id, album.img_id, album.img_url, album.thumb_url, album.img_original FROM " . $GLOBALS['ecs']->table('goods_gallery') . " AS album " . $GLOBALS['album_where']; $res = $GLOBALS['db']->SelectLimit($sql, $page_size, ($page - 1) * $page_size); while ($row = $GLOBALS['db']->fetchRow($res)) { $thumb_url = ''; $image = ''; /* 水印 */ if ($watermark && file_exists(ROOT_PATH . $row['img_original'])) { if (empty($row['img_url'])) { $dir = dirname(ROOT_PATH . $row['img_original']) . '/'; } else { $dir = dirname(ROOT_PATH . $row['img_url']) . '/'; } $file_name = cls_image::unique_name($dir); $file_name .= cls_image::get_filetype(empty($row['img_url']) ? $row['img_original'] : $row['img_url']); copy(ROOT_PATH . $row['img_original'], $dir . $file_name); $image = $GLOBALS['image']->add_watermark($dir . $file_name, '', $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']); if (!$image) { @unlink($dir . $file_name); $msg = sprintf($GLOBALS['_LANG']['error_pos'], $row['goods_id']) . "\n" . $GLOBALS['image']->error_msg(); if ($silent) { $GLOBALS['err_msg'][] = $msg; continue; } else { make_json_error($msg); } } /* 重新格式化图片名称 */ $image = reformat_image_name('gallery', $row['goods_id'], $image, 'goods'); if ($change || empty($row['img_url']) || $row['img_original'] == $row['img_url']) { if ($image != $row['img_url']) { $sql = "UPDATE " . $GLOBALS['ecs']->table('goods_gallery') . " SET img_url='{$image}' WHERE img_id='{$row['img_id']}'"; $GLOBALS['db']->query($sql); if ($row['img_original'] != $row['img_url']) { @unlink(ROOT_PATH . $row['img_url']); } } } else { replace_image($image, $row['img_url'], $row['goods_id'], $silent); } } /* 缩略图 */ if ($thumb) { if (empty($row['thumb_url'])) { $dir = dirname(ROOT_PATH . $row['img_original']) . '/'; } else { $dir = dirname(ROOT_PATH . $row['thumb_url']) . '/'; } $thumb_url = $GLOBALS['image']->make_thumb(ROOT_PATH . $row['img_original'], $GLOBALS['_CFG']['thumb_width'], $GLOBALS['_CFG']['thumb_height'], $dir); if (!$thumb_url) { $msg = sprintf($GLOBALS['_LANG']['error_pos'], $row['goods_id']) . "\n" . $GLOBALS['image']->error_msg(); if ($silent) { $GLOBALS['err_msg'][] = $msg; continue; } else { make_json_error($msg); } } /* 重新格式化图片名称 */ $thumb_url = reformat_image_name('gallery_thumb', $row['goods_id'], $thumb_url, 'thumb'); if ($change || empty($row['thumb_url'])) { if ($thumb_url != $row['thumb_url']) { $sql = "UPDATE " . $GLOBALS['ecs']->table('goods_gallery') . " SET thumb_url='{$thumb_url}' WHERE img_id='{$row['img_id']}'"; $GLOBALS['db']->query($sql); @unlink(ROOT_PATH . $row['thumb_url']); } } else { replace_image($thumb_url, $row['thumb_url'], $row['goods_id'], $silent); } } } } }
if ($_CFG['auto_generate_gallery'] && !empty($gallery_img)) { $goods_gallery['img_url'] = reformat_image_name('gallery', $goods_gallery['goods_id'], $gallery_img, 'goods'); } //设置商品图 $goods_img = reformat_image_name('goods', $goods_gallery['goods_id'], $field_arr['goods_img'], 'goods'); } if (!empty($field_arr['goods_thumb'])) { //设置商品相册缩略图 if ($_CFG['auto_generate_gallery']) { $ext = substr($field_arr['goods_thumb'], strrpos($field_arr['goods_thumb'], '.')); $gallery_thumb = dirname($field_arr['goods_thumb']) . '/' . $image->random_filename() . $ext; @copy(ROOT_PATH . $field_arr['goods_thumb'], ROOT_PATH . $gallery_thumb); $goods_gallery['thumb_url'] = reformat_image_name('gallery_thumb', $goods_gallery['goods_id'], $gallery_thumb, 'thumb'); } //设置商品缩略图 $goods_thumb = reformat_image_name('goods_thumb', $goods_gallery['goods_id'], $field_arr['goods_thumb'], 'thumb'); } //修改商品图 $db->query("UPDATE " . $ecs->table('goods') . " SET goods_img = '{$goods_img}', goods_thumb = '{$goods_thumb}', original_img = '{$original_img}' WHERE goods_id='" . $goods_gallery['goods_id'] . "'"); //添加商品相册图 if ($_CFG['auto_generate_gallery']) { $db->autoExecute($ecs->table('goods_gallery'), $goods_gallery, 'INSERT'); } } } } // 记录日志 admin_log('', 'batch_upload', 'goods'); /* 显示提示信息,返回商品列表 */ $link[] = array('href' => 'goods.php?act=list', 'text' => $_LANG['01_goods_list']); sys_msg($_LANG['batch_upload_ok'], 0, $link);
/** * 保存某商品的相册图片 * @param int $goods_id 商品id * @param int $goods_attr_id 商品属性id * @param array $image_files 商品图片信息 * @return void */ function handle_gallery_image_attr($goods_id, $goods_attr_id, $image_files) { /* 是否处理缩略图 */ $proc_thumb = isset($GLOBALS['shop_id']) && $GLOBALS['shop_id'] > 0 ? false : true; /* 是否成功上传 */ $flag = false; if (isset($image_files['error'])) { if ($image_files['error'] == 0) { $flag = true; } } else { if ($image_files['tmp_name'] != 'none') { $flag = true; } } if ($flag) { // 生成缩略图 if ($proc_thumb) { $thumb_url = $GLOBALS['image']->make_thumb($image_files['tmp_name'], $GLOBALS['_CFG']['thumb_width'], $GLOBALS['_CFG']['thumb_height']); $thumb_url = is_string($thumb_url) ? $thumb_url : ''; } //生成商品详情页图片 $img_url = $GLOBALS['image']->make_thumb($image_files['tmp_name'], $GLOBALS['_CFG']['image_width'], $GLOBALS['_CFG']['image_height']); $upload = array('name' => $image_files['name'], 'type' => $image_files['type'], 'tmp_name' => $image_files['tmp_name'], 'size' => $image_files['size']); if (isset($image_files['error'])) { $upload['error'] = $image_files['error']; } $img_original = $GLOBALS['image']->upload_image($upload); if ($img_original === false) { sys_msg($GLOBALS['image']->error_msg(), 1, array(), false); } if (!$proc_thumb) { $thumb_url = $img_original; } /* 重新格式化图片名称 */ $img_original = reformat_image_name('gallery', $goods_id, $img_original, 'source'); $img_url = reformat_image_name('gallery', $goods_id, $img_url, 'goods'); $thumb_url = reformat_image_name('gallery_thumb', $goods_id, $thumb_url, 'thumb'); $sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original, goods_attr_id) " . "VALUES ('{$goods_id}', '{$img_url}', '{$img_desc}', '{$thumb_url}', '{$img_original}', '{$goods_attr_id}')"; $GLOBALS['db']->query($sql); /* 不保留商品原图的时候删除原图 */ if ($proc_thumb && !$GLOBALS['_CFG']['retain_original_img'] && !empty($img_original)) { $GLOBALS['db']->query("UPDATE " . $GLOBALS['ecs']->table('goods_gallery') . " SET img_original='' WHERE `goods_id`='{$goods_id}'"); @unlink('../' . $img_original); } } return array('error' => 0, 'goods_id' => $goods_id, 'info' => 'succesful'); }
function getImg($url) { global $image, $_CFG; //判断是否$url前面有http $qz = substr($url, 0, 2); if (strtolower($qz) == '//') { $url = 'https:' . $url; } $fileName = ROOT_PATH . '/images/taobao/'; $arr = explode('.', $url); $ext = end($arr); $uniq = md5($url); //设置一个唯一id $name = $fileName . $uniq . '.' . $ext; //图像保存的名称和路径 $img = file_get_contents_curl($url); file_put_contents($name, $img); $thumb_url = $image->make_thumb($name, $_CFG['thumb_width'], $_CFG['thumb_height']); $img_url = $image->make_thumb($name, $_CFG['image_width'], $_CFG['image_height']); $img_original = $image->make_thumb($name); $img_original = reformat_image_name('gallery', $gid, $img_original, 'source'); $img_url = reformat_image_name('gallery', $gid, $img_url, 'goods'); $thumb_url = reformat_image_name('gallery_thumb', $gid, $thumb_url, 'thumb'); return array('source' => $img_original, 'goods' => $img_url, 'thumb' => $thumb_url); //return $name; }
/** * 保存某商品的相册图片 * @param int $goods_id * @param array $image_files * @param array $image_descs * @return void */ function handle_gallery_image($goods_id, $image_files, $image_descs) { /* 是否处理缩略图 */ $proc_thumb = isset($GLOBALS['shop_id']) && $GLOBALS['shop_id'] > 0 ? false : true; foreach ($image_descs as $key => $img_desc) { /* 是否成功上传 */ $flag = false; if (isset($image_files['error'])) { if ($image_files['error'][$key] == 0) { $flag = true; } } else { if ($image_files['tmp_name'][$key] != 'none') { $flag = true; } } if ($flag) { // 生成缩略图 if ($proc_thumb) { $thumb_url = $GLOBALS['image']->make_thumb($image_files['tmp_name'][$key], $GLOBALS['_CFG']['thumb_width'], $GLOBALS['_CFG']['thumb_height']); $thumb_url = is_string($thumb_url) ? $thumb_url : ''; } $upload = array('name' => $image_files['name'][$key], 'type' => $image_files['type'][$key], 'tmp_name' => $image_files['tmp_name'][$key], 'size' => $image_files['size'][$key]); if (isset($image_files['error'])) { $upload['error'] = $image_files['error'][$key]; } $img_original = $GLOBALS['image']->upload_image($upload); if ($img_original === false) { sys_msg($GLOBALS['image']->error_msg(), 1, array(), false); } $img_url = $img_original; if (!$proc_thumb) { $thumb_url = $img_original; } // 如果服务器支持GD 则添加水印 if ($proc_thumb && gd_version() > 0) { $pos = strpos(basename($img_original), '.'); $newname = dirname($img_original) . '/' . $GLOBALS['image']->random_filename() . substr(basename($img_original), $pos); copy('../' . $img_original, '../' . $newname); $img_url = $newname; $GLOBALS['image']->add_watermark('../' . $img_url, '', $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']); } /* 重新格式化图片名称 */ $img_original = reformat_image_name('gallery', $goods_id, $img_original, 'source'); $img_url = reformat_image_name('gallery', $goods_id, $img_url, 'goods'); $thumb_url = reformat_image_name('gallery_thumb', $goods_id, $thumb_url, 'thumb'); $sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original) " . "VALUES ('{$goods_id}', '{$img_url}', '{$img_desc}', '{$thumb_url}', '{$img_original}')"; $GLOBALS['db']->query($sql); } } }
} if ($goods_middle !== false) { $db->query("UPDATE " . $ecs->table('goods') . " SET goods_middle = '{$goods_middle}' WHERE goods_id='{$goods_id}'"); } /* 如果有图片,把商品图片加入图片相册 */ if (isset($img)) { /* 重新格式化图片名称 */ if (empty($is_url_goods_img)) { $img = reformat_image_name('gallery', $goods_id, $img, 'source'); $gallery_img = reformat_image_name('gallery', $goods_id, $gallery_img, 'goods'); } else { $img = $url_goods_img; $gallery_img = $url_goods_img; } $gallery_thumb = reformat_image_name('gallery_thumb', $goods_id, $gallery_thumb, 'thumb'); $gallery_middle = reformat_image_name('gallery_middle', $goods_id, $gallery_middle, 'middle'); $sql = "INSERT INTO " . $ecs->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, middle_url, img_original) " . "VALUES ('{$goods_id}', '{$gallery_img}', '', '{$gallery_thumb}', '{$gallery_middle}', '{$img}')"; $db->query($sql); } /* 处理相册图片 */ handle_gallery_image($goods_id, $_FILES['img_url'], $_POST['img_desc'], $_POST['img_file']); /* 编辑时处理相册图片描述 */ if (!$is_insert && isset($_POST['old_img_desc'])) { foreach ($_POST['old_img_desc'] as $img_id => $img_desc) { $sql = "UPDATE " . $ecs->table('goods_gallery') . " SET img_desc = '{$img_desc}' WHERE img_id = '{$img_id}' LIMIT 1"; $db->query($sql); } } /* 不保留商品原图的时候删除原图 */ if ($proc_thumb && !$_CFG['retain_original_img'] && !empty($original_img)) { $db->query("UPDATE " . $ecs->table('goods') . " SET original_img='' WHERE `goods_id`='{$goods_id}'");
} } session_start(); require dirname(__FILE__) . '/includes/init.php'; require_once ROOT_PATH . '/' . ADMIN_PATH . '/includes/lib_goods.php'; include_once ROOT_PATH . '/includes/cls_image.php'; $image = new cls_image($_CFG['bgcolor']); $goods_id = $_REQUEST['goods_id']; /* 创建当月目录 */ $dir = date('Ym'); $dir = ROOT_PATH . $image->images_dir . '/' . $dir . '/'; create_folders($dir); $img_name = $GLOBALS['image']->unique_name($dir); $img_name = $dir . $img_name . $GLOBALS['image']->get_filetype($_FILES['Filedata']['name']); move_upload_file($_FILES['Filedata']['tmp_name'], $img_name); $img_original = str_replace(ROOT_PATH, '', $img_name); $thumb_url = $GLOBALS['image']->make_thumb('../' . $img_original, $GLOBALS['_CFG']['thumb_width'], $GLOBALS['_CFG']['thumb_height']); $pos = strpos(basename($img_original), '.'); $newname = dirname($img_original) . '/' . $GLOBALS['image']->random_filename() . substr(basename($img_original), $pos); copy('../' . $img_original, '../' . $newname); $img_url = $newname; $GLOBALS['image']->add_watermark('../' . $img_url, '', $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']); $img_original = reformat_image_name('gallery', $goods_id, $img_original, 'source'); $img_url = reformat_image_name('gallery', $goods_id, $img_url, 'goods'); $thumb_url = reformat_image_name('gallery_thumb', $goods_id, $thumb_url, 'thumb'); $sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original) " . "VALUES ('{$goods_id}', '{$img_url}', '{$img_desc}', '{$thumb_url}', '{$img_original}')"; $db->query($sql); function create_folders($dir) { return is_dir($dir) or create_folders(dirname($dir)) and mkdir($dir, 0777); }