public function add_goods() { $image_root = C('Goods_image_path'); $image_common = C('Goods_image_common'); //组装上传路径 //$upload_path=$image_root.'/'.$image_common; //echo $upload_path; $date_dir = date("Y-m"); if (!file_exists($image_root . '/' . $date_dir)) { mkdir($image_root . '/' . $date_dir); mkdir($image_root . '/' . $date_dir . '/common/'); mkdir($image_root . '/' . $date_dir . '/big/'); mkdir($image_root . '/' . $date_dir . '/small/'); mkdir($image_root . '/' . $date_dir . '/middle/'); } import('ORG.Net.UploadFile'); $upload = new UploadFile(); $upload->maxSize = C('Goods_image_max'); $upload->allowExts = C('allowExts'); $upload->savePath = $image_root . '/' . $date_dir . '/common/'; if (!$upload->upload()) { echo "<script>alert('上传失败')</script>"; $this->redirect('Goods/addBook'); } //获取上传信息 $info = $upload->getUploadFileInfo(); $save_path = $info[0]['savepath']; $save_name = $info[0]['savename']; //真正的上传路径 $upload_path = $save_path . $save_name; //调用生成缩略图函数 thumb_images($upload_path); $goods_add = M("Goods"); $_POST['image'] = $date_dir . "_" . $save_name; $data = $_POST; $res = $goods_add->add($data); return $res; }
public function doAddBook() { $this->init(); if (empty($_POST['name']) || empty($_POST['classify_id']) || !isset($_POST['qd_id']) || empty($_POST['price']) || empty($_POST['qd_price']) || empty($_POST['reserve']) || empty($_FILES['image']) || empty($_POST['description'])) { echo "<script>alert('信息填写不正确')</script>"; $this->redirect('Goods/addBook'); } $image_root = C('Goods_image_path'); $image_common = C('Goods_image_common'); //组装上传路径 //$upload_path=$image_root.'/'.$image_common; //echo $upload_path; $date_dir = date("Y-m"); if (!file_exists($image_root . '/' . $date_dir)) { mkdir($image_root . '/' . $date_dir); mkdir($image_root . '/' . $date_dir . '/common/'); mkdir($image_root . '/' . $date_dir . '/big/'); mkdir($image_root . '/' . $date_dir . '/small/'); mkdir($image_root . '/' . $date_dir . '/middle/'); } import('ORG.Net.UploadFile'); $upload = new UploadFile(); $upload->maxSize = C('Goods_image_max'); $upload->allowExts = C('allowExts'); $upload->savePath = $image_root . '/' . $date_dir . '/common/'; if (!$upload->upload()) { echo "<script>alert('上传失败')</script>"; $this->redirect('Goods/addBook'); } //获取上传信息 $info = $upload->getUploadFileInfo(); $save_path = $info[0]['savepath']; $save_name = $info[0]['savename']; //真正的上传路径 $upload_path = $save_path . $save_name; //调用生成缩略图函数 thumb_images($upload_path); $goods_add = M("Goods"); $_POST['image'] = $date_dir . "_" . $save_name; $data = $_POST; $res = $goods_add->add($data); if ($res) { echo "<script>alert('添加成功')</script>"; $this->redirect('Goods/book'); } else { $this->error('添加失败'); } }