public function add() { $bp = M('Banner_page'); $banner_page = $bp->select(); $data = array('banner_page' => $banner_page); if (IS_POST) { $banner = M('Banner'); $thumb = imgFile(); $info = $thumb['info']; if (!$info) { // 上传错误提示错误信息 $error; } else { // 上传成功 $path = $info['ban_url']['savepath']; $p = ltrim($path, '.'); $img = $info['ban_url']['savename']; $src = $p . $img; $root = rtrim($thumb['rootPath'], '\\ThinkPHP/'); $roo = str_replace("\\", "/", $root); $url = ltrim($info['ban_url']['savepath'], '.'); $uploadedfile = $roo . $url . $info['ban_url']['savename']; $tmp = imagecreatefromjpeg($uploadedfile); list($width, $height) = getimagesize($uploadedfile); $newwidth = 1903; $newheight = $height / $width * $newwidth; img_create_small($uploadedfile, $newwidth, $newheight, $uploadedfile); $arr = array('ban_name' => I('post.ban_name'), 'ban_order' => I('post.ban_order'), 'ban_gourl' => I('post.ban_gourl'), 'ban_url' => $src, 'ban_pageid' => I('post.check_page')); $res = $banner->add($arr); if ($res) { echo "<script>window.location.href='/index.php/Admin/Photo/index';</script>"; } else { echo "<script>alert('添加失败');window.history.go(-1);</script>"; } } } $this->assign($data); $this->display(); }
function add() { $artcate = M('artcate'); $article = M('article'); $cate = $artcate->where(array('cate_pid' => 0))->order('cate_id ASC')->select(); $maxorder = $article->field('art_order')->order('art_order DESC')->limit(1)->find(); //文章列表的最大排序 // dump($maxorder);die; if (!$maxorder) { $order = 1; } else { $order = $maxorder['art_order'] + 1; } $time = time(); $nowtime = date('Y-m-d', $time); $arr = array(); if (IS_POST) { $arr = array('art_title' => I('post.title'), 'art_author' => I('post.author'), 'art_from' => I('post.source'), 'art_isshow' => I('post.isshow'), 'art_summary' => I('post.summary'), 'art_content' => I('post.content1'), 'art_addtime' => $nowtime, 'art_order' => $order); // print_r($arr);die; $scate = I('post.scate'); $acate = I('post.cate'); if (!$scate) { $arr['art_cateid'] = $acate; } else { $arr['art_cateid'] = $scate; } // dump($arr);die; $res = $article->add($arr); // dump($res);die; if (FALSE) { $this->error('更新失败!'); } else { if ($_FILES['thumb']['name']) { import('ORG.Net.UploadFile'); $thumb = imgFile(); // $thumb->thumbMaxWidth='100'; $info = $thumb['info']; if (!$info) { // 上传错误提示错误信息 $error; } else { // 上传成功 $path = $info['thumb']['savepath']; $p = ltrim($path, '.'); $img = $info['thumb']['savename']; $src = $p . $img; $root = rtrim($thumb['rootPath'], '\\ThinkPHP/'); $roo = str_replace("\\", "/", $root); $url = ltrim($info['thumb']['savepath'], '.'); $uploadedfile = $roo . $url . $info['thumb']['savename']; $oldFile = $roo . $art['art_thumb']; unlink($oldFile); //删除原来的缩略图 $tmp = imagecreatefromjpeg($uploadedfile); list($width, $height) = getimagesize($uploadedfile); $newwidth = 100; $newheight = $height / $width * $newwidth; img_create_small($uploadedfile, $newwidth, $newheight, $uploadedfile); $article->where(array('art_id' => $res))->save(array('art_thumb' => $src)); echo "<script>window.location.href='/index.php/Admin/Article/index';</script>"; } } else { echo "<script>window.location.href='/index.php/Admin/Article/index';</script>"; } } } $data = array('cate' => $cate, 'time' => $time); $this->assign($data); $this->display(); }
public function add() { $procate = M('procate'); $product = M('product'); $cate = $procate->where(array('cate_pid' => 0))->order('cate_id ASC')->select(); $maxorder = $product->field('pro_order')->order('pro_order DESC')->limit(1)->find(); //文章列表的最大排序 // dump($maxorder);die; if (!$maxorder) { $order = 1; } else { $order = $maxorder['pro_order'] + 1; } $time = time(); $arr = array(); if (IS_POST) { $arr = array('pro_name' => I('post.title'), 'pro_cate_id' => I('post.cate'), 'pro_author' => I('post.author'), 'pro_isshow' => 1, 'pro_member_price' => I('post.member_price'), 'pro_general_price' => I('post.general_price'), 'pro_from' => I('post.source'), 'pro_summary' => I('post.summary'), 'pro_order' => I('post.order'), 'pro_introduction' => I('post.content1'), 'pro_addtime' => time()); $scate = I('post.scate'); $acate = I('post.cate'); if (!$scate) { $arr['pro_cate_id'] = $acate; } else { $arr['pro_cate_id'] = $scate; } // dump($arr);die; $res = $product->add($arr); // dump($res);die; if (!$res) { $this->error('更新失败!'); } else { if ($_FILES['thumb']['name']) { $thumb = imgFile(); $info = $thumb['info']; if (!$info) { // 上传错误提示错误信息 $error; } else { // 上传成功 $path = $info['thumb']['savepath']; $p = ltrim($path, '.'); $img = $info['thumb']['savename']; $src = $p . $img; $root = rtrim($upload->rootPath, '\\ThinkPHP/'); $roo = str_replace("\\", "/", $root); $url = ltrim($info['thumb']['savepath'], '.'); $uploadedfile = $roo . $url . $info['thumb']['savename']; $oldFile = $roo . $pro['pro_thumb']; unlink($oldFile); //删除原来的缩略图 $tmp = imagecreatefromjpeg($uploadedfile); list($width, $height) = getimagesize($uploadedfile); $newwidth = 100; $newheight = $height / $width * $newwidth; img_create_small($uploadedfile, $newwidth, $newheight, $uploadedfile); $product->where(array('pro_id' => $res))->save(array('pro_thumb' => $src)); echo "<script>window.location.href='/Admin/Product/index';</script>"; } } else { echo "<script>window.location.href='/Admin/Product/index';</script>"; } } } $data = array('cate' => $cate, 'time' => $time); $this->assign($data); $this->display(); }