使用封装图片类上传图片

function save_image_upload($upd_file, $key='',$dir='temp', $whs=array(),$is_water=false,$need_return = false)
{
require_once APP_ROOT_PATH."system/utils/es_imagecls.php";
$image = new es_imagecls();
$image->max_size = intval(app_conf("MAX_IMAGE_SIZE"));

$list = array();


if(empty($key))
{
foreach($upd_file as $fkey=>$file)
{
$list[$fkey] = false;
$image->init($file,$dir);
if($image->save())
{
$list[$fkey] = array();
$list[$fkey]['url'] = $image->file['target'];
$list[$fkey]['path'] = $image->file['local_target'];
$list[$fkey]['name'] = $image->file['prefix'];
}
else
{
if($image->error_code==-105)
{
if($need_return)
{
return array('error'=>1,'message'=>'上传的图片太大');
}
else
echo "上传的图片太大";
}
elseif($image->error_code==-104||$image->error_code==-103||$image->error_code==-102||$image->error_code==-101)
{
if($need_return)
{
return array('error'=>1,'message'=>'非法图像');
}
else
echo "非法图像";
}
exit;
}
}
}
else
{
$list[$key] = false;
$image->init($upd_file[$key],$dir);
if($image->save())
{
$list[$key] = array();
$list[$key]['url'] = $image->file['target'];
$list[$key]['path'] = $image->file['local_target'];
$list[$key]['name'] = $image->file['prefix'];
}
else
{
if($image->error_code==-105)
{
if($need_return)
{
return array('error'=>1,'message'=>'上传的图片太大');
}
else
echo "上传的图片太大";
}
elseif($image->error_code==-104||$image->error_code==-103||$image->error_code==-102||$image->error_code==-101)
{
if($need_return)
{
return array('error'=>1,'message'=>'非法图像');
}
else
echo "非法图像";
}
exit;
}
}


$water_image = APP_ROOT_PATH.app_conf("WATER_MARK");
$alpha = app_conf("WATER_ALPHA");
$place = app_conf("WATER_POSITION");

foreach($list as $lkey=>$item)
{
//循环生成规格图
foreach($whs as $tkey=>$wh)
{
$list[$lkey]['thumb'][$tkey]['url'] = false;
$list[$lkey]['thumb'][$tkey]['path'] = false;
if($wh[0] > 0 || $wh[1] > 0)  //有宽高度
{
$thumb_type = isset($wh[2]) ? intval($wh[2]) : 0;  //剪裁还是缩放, 0缩放 1剪裁
if($thumb = $image->thumb($item['path'],$wh[0],$wh[1],$thumb_type))
{
$list[$lkey]['thumb'][$tkey]['url'] = $thumb['url'];
$list[$lkey]['thumb'][$tkey]['path'] = $thumb['path'];
if(isset($wh[3]) && intval($wh[3]) > 0)//需要水印
{
$paths = pathinfo($list[$lkey]['thumb'][$tkey]['path']);
$path = $paths['dirname'];
        $path = $path."/origin/";
        if (!is_dir($path)) { 
            @mkdir($path);
            @chmod($path, 0777);
  }      
        $filename = $paths['basename'];
@file_put_contents($path.$filename,@file_get_contents($list[$lkey]['thumb'][$tkey]['path']));      
$image->water($list[$lkey]['thumb'][$tkey]['path'],$water_image,$alpha, $place);
}
}
}
}
if($is_water)
{
$paths = pathinfo($item['path']);
$path = $paths['dirname'];
        $path = $path."/origin/";
        if (!is_dir($path)) { 
            @mkdir($path);
            @chmod($path, 0777);
  }      
        $filename = $paths['basename'];
@file_put_contents($path.$filename,@file_get_contents($item['path']));        
$image->water($item['path'],$water_image,$alpha, $place);
}
}
return $list;
}


{
return array('error'=>1,'message'=>'非法图像');
}
else
echo "非法图像";
}
exit;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值