/** * [articel_add 添加文章] * @return [type] [description] */ public function articel_add() { if (IS_POST) { //实例化上传类 $storage = new \Upload\Storage\FileSystem(__UPLOAD__); $file = new \Upload\File('foo', $storage); $fileName = $file->getNameWithExtension(); if (!empty($fileName)) { // Optionally you can rename the file on upload $new_filename = uniqid(); $file->setName($new_filename); // Validate file upload // MimeType List => http://www.webmaster-toolkit.com/mime-types.shtml $file->addValidations([new \Upload\Validation\Mimetype(['image/png', 'image/gif', 'image/jpeg', 'image/jpg']), new \Upload\Validation\Size('5M')]); // Access data about the file that has been uploaded $data = ['name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions()]; // Try to upload file try { // Success! $file->upload(); $arcData = ['title' => $_POST['title'], 'thumb' => $data['name'], 'keywords' => $_POST['keywords'], 'content' => $_POST['content'], 'description' => $_POST['description'], 'category_id' => $_POST['category_id'], 'click' => $_POST['click'], 'writer' => $_POST['writer'], 'source' => $_POST['source'], 'pubdate' => time()]; Article::firstOrCreate($arcData); View::success('添加成功'); die; } catch (\Exception $e) { // Fail! $errors = $file->getErrors(); print_r($errors); View::error($errors['0']); die; } } else { $arcData = ['title' => $_POST['title'], 'keywords' => $_POST['keywords'], 'content' => $_POST['content'], 'description' => $_POST['description'], 'category_id' => $_POST['category_id'], 'click' => $_POST['click'], 'writer' => $_POST['writer'], 'source' => $_POST['source'], 'pubdate' => time()]; Article::firstOrCreate($arcData); View::success('添加成功'); die; } } $topcate = Category::where(['pid' => 0, 'is_del' => 0])->get()->toArray(); //组合分类数据 foreach ($topcate as $k => $v) { $soncate = Category::where(['pid' => $v['id'], 'is_del' => 0])->get()->toArray(); $topcate[$k]['soncate'] = $soncate; } $allcate = $topcate; $this->smarty->assign('title', '文添加文章_ISisWeb中文网后台管理_ISirPHPFramework'); $this->smarty->assign('cate', $allcate); $this->smarty->display('Admin/Article/add.html'); // die(); // $this->view = View::make('/Admin/Article/add') // ->with('cate',$allcate) // ->with('title','添加文章_ISirWeb中文网后台'); }