function get_img($img_url = '') { $cls_imageobj = new cls_image(); $data = file_get_contents($img_url); $dir = date('Ym'); $filename = cls_image::random_filename(); $imgDir = $cls_imageobj->images_dir . '/' . $dir . '/source_img/' . $filename . '.jpg'; $dir = ROOT_PATH . $imgDir; $fp = @fopen($dir, "w"); @fwrite($fp, $data); fclose($fp); return $imgDir; }
$old_original_img = ''; // 初始化原始图片旧图 // 如果上传了商品图片,相应处理 if ($_FILES['goods_img']['tmp_name'] != '' && $_FILES['goods_img']['tmp_name'] != 'none') { $original_img = $image->upload_image($_FILES['goods_img']); // 原始图片 if ($original_img === false) { sys_msg($image->error_msg(), 1, array(), false); } $goods_img = $original_img; // 商品图片 /* 复制一份相册图片 */ $img = $original_img; // 相册图片 $pos = strpos(basename($img), '.'); $newname = dirname($img) . '/' . $image->random_filename() . substr(basename($img), $pos); if (!copy('../' . $img, '../' . $newname)) { sys_msg('fail to copy file: ' . realpath('../' . $img), 1, array(), false); } $img = $newname; $gallery_img = $img; $gallery_thumb = $img; // 如果系统支持GD,缩放商品图片,且给商品图片和相册图片加水印 if ($image->gd_version() > 0 && $image->check_img_function($_FILES['goods_img']['type'])) { // 如果设置大小不为0,缩放图片 if ($_CFG['image_width'] != 0 || $_CFG['image_height'] != 0) { $goods_img = $image->make_thumb('../' . $goods_img, $GLOBALS['_CFG']['image_width'], $GLOBALS['_CFG']['image_height']); if ($goods_img === false) { sys_msg($image->error_msg(), 1, array(), false); } }
/** * 生成指定目录不重名的文件名 * * @access public * @param string $dir 要检查是否有同名文件的目录 * * @return string 文件名 */ function unique_name($dir) { $filename = ''; while (empty($filename)) { $filename = cls_image::random_filename(); if (is_file($dir . $filename . '.jpg') || file_exists($dir . $filename . '.gif') || is_file($dir . $filename . '.png')) { $filename = ''; } } return $filename; }
function upload_article_file($upload) { if (!make_dir("../" . DATA_DIR . "/article")) { /* 创建目录失败 */ return false; } $filename = cls_image::random_filename() . substr($upload['name'], strpos($upload['name'], '.')); $path = ROOT_PATH . DATA_DIR . "/article/" . $filename; if (move_upload_file($upload['tmp_name'], $path)) { return DATA_DIR . "/article/" . $filename; } else { return false; } }
$field_arr['goods_number'] = 0; } $db->autoExecute($ecs->table('goods'), $field_arr, 'INSERT'); $max_id = $db->insert_id() + 1; /* 如果图片不为空,修改商品图片,插入商品相册*/ if (!empty($field_arr['original_img']) || !empty($field_arr['goods_img']) || !empty($field_arr['goods_thumb'])) { $goods_img = ''; $goods_thumb = ''; $original_img = ''; $goods_gallery = array(); $goods_gallery['goods_id'] = $db->insert_id(); if (!empty($field_arr['original_img'])) { //设置商品相册原图和商品相册图 if ($_CFG['auto_generate_gallery']) { $ext = substr($field_arr['original_img'], strrpos($field_arr['original_img'], '.')); $img = dirname($field_arr['original_img']) . '/' . $image->random_filename() . $ext; $gallery_img = dirname($field_arr['original_img']) . '/' . $image->random_filename() . $ext; @copy(ROOT_PATH . $field_arr['original_img'], ROOT_PATH . $img); @copy(ROOT_PATH . $field_arr['original_img'], ROOT_PATH . $gallery_img); $goods_gallery['img_original'] = reformat_image_name('gallery', $goods_gallery['goods_id'], $img, 'source'); } //设置商品原图 if ($_CFG['retain_original_img']) { $original_img = reformat_image_name('goods', $goods_gallery['goods_id'], $field_arr['original_img'], 'source'); } else { @unlink(ROOT_PATH . $field_arr['original_img']); } } if (!empty($field_arr['goods_img'])) { //设置商品相册图 if ($_CFG['auto_generate_gallery'] && !empty($gallery_img)) {
/** * 处理url图片 * @$img_url 图片地址 * @$mark 是否处理缩略图 1不处理 **/ function get_img($img_url = '', $mark = '0') { $cls_imageobj = new cls_image(); if (strstr($img_url, 'http://')) { $data = file_get_contents($img_url); $dir = date('Ym'); $filename = cls_image::random_filename(); $imgDir = $cls_imageobj->images_dir . '/' . $dir . '/source_img/' . $filename . '.jpg'; $dir = ROOT_PATH . $imgDir; $fp = @fopen($dir, "w"); @fwrite($fp, $data); fclose($fp); } else { $imgDir = $img_url; } if ($mark == '0') { //处理缩略图 $goods_thumb = ''; $goods_img = ''; $goods_thumb = $cls_imageobj->make_thumb('http://o2o.txd168.com/' . $imgDir, "170", '170'); $goods_img = $cls_imageobj->make_thumb('http://o2o.txd168.com/' . $imgDir, "300", '300'); return array('original_img' => $imgDir, 'goods_thumb' => $goods_thumb, 'goods_img' => $goods_img); } elseif ($mark == '1') { return $imgDir; } }