ThinkPHP将上传问件添加到数据库

<?php

namespace Home\Controller; /*****************

use Think\Controller; ****命名空间****/

class MessageController extends Controller {

public function doMess(){
$upload = new \Think\Upload();// 实例化上传类  
$upload->maxSize = 43145728 ; 
$upload->rootPath  =     './Public/Uploads/';

$info   =   $upload->upload();    
if(!$info) {       
$this->error($upload->getError()); 
}else{
$this->success('上传成功!'); 
}

$message = D('Messages');

$message -> create();//必须放在实例化之后

$message->filename = $info['filename']['savename'];//获取上传文件名
$message->time=time();
$message->uid=$_SESSION['id'];

$lastId = $message -> add();
if($lastId){
$this -> success('留言成功');
}else{
$this -> error('留言失败');
}
}
}

?>
 
posted @ 2016-04-10 10:26  刘国坤  阅读(187)  评论(0编辑  收藏  举报