会议记录管理系统(4) - 会议记录添加模块

1.会议记录添加模块概述
系统正常登录后,每一个用户都有权利添加新的会议,供本部门成员和其他部门成员阅读浏览。

2.会议记录信息验证技术
向数据库中添加新会议记录时,系统必须保证用户提交的信息不为空。这里应用JavaScript脚本判断上传数据是否为空,在js文件夹下创建add_meeting.js文件,编写check_submit()方法,验证表单提交的数据是否为空。关键代码如下:

function check_submit(){
    if(theForm.meeting_name.value==""){
        alert("会议名称不能为空!");
        theForm.meeting_name.focus();
        return false;
    }
    if(theForm.meeting_place.value==""){
        alert("会议地点不能为空!");
        theForm.meeting_place.focus();
        return false;
    }
    if(theForm.meeting_host.value==""){
        alert("会议主持人不能为空!");
        theForm.meeting_host.focus();
        return false;
    }
    if(theForm.meeting_saver.value==""){
        alert("会议记录人不能为空!");
        theForm.meeting_saver.focus();
        return false;
    }
    if(theForm.meeting_present.value==""){
        alert("出席人员不能为空!");
        theForm.meeting_present.focus();
        return false;
    }
    if(theForm.textarea.value==""){
        alert("会议摘要不能为空!");
        theForm.textarea.focus();
        return false;
    }
    theForm.submit();     // 表单提交
}

3.上传文件处理技术
本系统要求用户在上传会议记录的同时,必须上传文本文档格式的会议记录附件。所以又增加了上传文件和判断上传文件格式两项技术。
A.文件上传
文件上传应用的是move_uploaded_file函数和 FILES[]1)moveuploadedfile()moveuploadedfile()truefalseboolmoveuploadedfile(stringfilename,stringdestination)filename _FILES[tmp_name];参数destination指文件上传后保存的新路径和名称。
注意:如果filename不是合法的上传文件,不会执行任何操作,move_uploaded_file()将返回false,如果参数filename是合法的上传文件,但出于某些原因无法移动,同样也不会执行任何操作,move_uploaded_file()将返回false.此外还会发出一条警告。
2)$_FILES全局变量
这里写图片描述

B.判断上传文件格式
用如下自定义函数完成,该函数存储于addmeeting_chk.php文件中,关键代码如下:

function f_postfix($f_type,$f_upfiles){     // 获取传递的参数值
    $is_pass = false;
    $tmp_upfiles = split("\.",$f_upfiles);  // 获取上传文件的后缀
    $tmp_num = count($tmp_upfiles);          // 统计返回值的元素数量
    // 循环读取定义文件类型数组的值
    for($num = 0;$num < count($f_type);$num++){
    // 完成文件类型的大小写转换及判断
    if(strtolower($tmp_upfiles[$tmp_num - 1]) == $f_type["num"]){
        $is_pass = $f_type["num"];  // 获取文件类型
    }
    }
        return $is_pass;     // 返回上传文件的类型
}

4.会议记录添加的实现过程
会议记录添加的操作是通过addmeeting.php与addmeeting_chk.php两个文件来实现的。
(1)在addmeeting.php文件中,创建添加会议记录信息的表单,通过JavaScript脚本对提交的元素进行判断,并且设置action属性值为addmeeting_chk.php。其关
关键代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
    <script>
    function checkSubmit(){

        if(theForm.meeting_name.value==""){

            alert("会议名称不能为空!");
            theForm.meeting_name.focus();
            return false;
        }
        // if(theForm.meeting_place.value=""){
        //     alert("会议地点不能为空!");
        //     theForm.meeting_place.focus();
        //     return false;
        // }
        // if(theForm.meeting_host.value=""){
        //     alert("会议主持人不能为空!");
        //     theForm.meeting_host.focus();
        //     return false;
        // }
        // if(theForm.meeting_saver.value=""){
        //     alert("会议记录人不能为空!");
        //     theForm.meeting_saver.focus();
        //     return false;
        // }
        if(theForm.meeting_present.value==""){
            alert("出席人员不能为空!");
            theForm.meeting_present.focus();
            return false;
        }
        if(theForm.textarea.value==""){
            alert("会议摘要不能为空!");
            theForm.textarea.focus();
            return false;
        }
        theForm.submit();     // 表单提交
}
</script>
<table cellpadding="0" cellspacing="0" border="0">
    <form id="theForm" name="theForm" action="addmeeting_chk.php" method="post" onsubmit="return checkSubmit();" enctype="multipart/form-data">
        <tr>
            <td colspan="3" height="32">
                <h1 align="center">添加会议记录</h1>
            </td>
        </tr>
        <tr>
            <td width="120" height="28"><div align="center">会议名称:</div></td>
            <td><input class="input2" type="text" name="meeting_name" /></td>
            <td align="left" width="180"><span class="spl">*填写会议记录名称</span></td>
        </tr>
        <!-- 省略部分代码 -->
        <tr>
            <td height="28"><div align="center">出席人员:</div></td>
            <td><input class="input2" type="text" name="meeting_present" /></td>
            <td align="left" width="180"><span class="spl">*填写会议出席人员</span></td>
        </tr>
        <tr>
            <td height="28">上传会议内容</td>
            <td>
                <input class="upload" name="meeting_documents" type="file" size="16" />
            </td>
            <td align="left" width="180"><span class="spl">*上传txt格式会议文稿</span></td>
        </tr>
        <tr>
            <td><div align="center">会议摘要:</div></td>
            <td height="70">
                <textarea style="width:170px;border:1px solid #ccc;" name="textarea" rows="4"></textarea>
            </td>
            <td align="left" width="180"><span class="spl">*填写会议记录摘要</span></td>
        </tr>
        <tr><td height="12" colspan="3"></td></tr>
        <td height="30" colspan="2">
            <center>
                <input class="add_mbtn1" type="submit" value="提交" />
                &nbsp;&nbsp;&nbsp;&nbsp;<input class="add_mbtn2" type="reset" value="重置" />
            </center>
        </td>
    </form>
</table>
</body>
</html>


(2)创建addmeeting_chk.php文件,接收表单提交的数据。首先,定义自定义函数用于验证上传文件的格式;然后对上传文件进行验证操作;最后,通过move_upload_file()函数执行文件的上传操作,并且将会议记录添加到指定的数据表中。其关键代码如下:

<?php
    header("Content-Type:text/html;charset=utf-8");
    date_default_timezone_set('PRC');           // 设置为北京时间

    session_start();
    include_once("conn/conn.php");

    // 判断上传格式是否符合上传要求
    function f_postfix($f_type,$f_upfiles){
        $is_pass = false;               // 表示上传的文件格式非法
        $tmp_upfiles = split("\.",$f_upfiles);          // 返回由文件名和文件后缀组成的数组

        $tmp_num = count($tmp_upfiles);                 // 返回数组长度


        $f_typeLen = count($f_type);



        for($num = 0;$num < $f_typeLen;$num++){
            $wjhz = $tmp_upfiles[$tmp_num - 1];         // 返回文件后缀
            if(strtolower($wjhz) == $f_type[$num]){
                $is_pass = $f_type[$num];              // 文件后缀合法
            }
        }
        return $is_pass;
    }

    // 判断是否上传了文件
    if($_FILES["meeting_documents"]["size"] <= 0){      // $_FILES["meeting_documents"]["size"]返回文件字节大小
        echo "<script>alert('请上传文件');history.go(-1);</script>";
    }else{
        // 如果上传了文件
        $f_type = array("txt");                         // 定义上传文件的格式
        $record_path = "upfile";                        // 定义上传路径

        $fileName = $_FILES["meeting_documents"]["name"];

        $postf = f_postfix($f_type,$fileName);

        // 判断上传格式
        if($postf != false){
            $new_path = time().".txt";                  // 以时间戳定义上传文件名称

            // 判断用户上传文件大小是否超过10MB
            if($_FILES["meeting_documents"]["size"] > 0 and $_FILES["meeting_documents"]["size"] < 1000000){

                // 定义上传文件在服务端的路径
                $filepath = $record_path . "\\" . $new_path;        // upfile...
                $filepath = addslashes($filepath);                  // addslashes函数,防止数据插入数据库时,斜杠被过滤掉
                echo "文件服务端路径为:".$filepath."<br />";

                // 数据库操作命令
                $sqlstrii = "insert into tb_meeting_info(meeting_name,meeting_present,meeting_abstruct,meeting_address)
                values('$_POST[meeting_name]','$_POST[meeting_present]','$_POST[textarea]','$filepath)')";

                // echo $sqlstrii;

                // 插入数据库
                if( mysql_query($sqlstrii)){
                    // 上传文件操作
                    // $_FILES["meeting_documents"]["tmp_name"],存储文件在临时目录中使用的文件名。因为文件在上传时,首先要以临时文件的身份保存在临时目录中。
                    move_uploaded_file($_FILES["meeting_documents"]["tmp_name"],$filepath);
                    echo "<script>alert('数据库添加成功!');history.go(-1);</script>";
                }else{
                     echo "<script>alert('数据库添加失败!');history.go(-1);</script>";
                }

            }else{
                echo "<script>alert('文件大小超过10MB');history.go(-1);</script>";
            }

        }else{
            echo "<script>alert('上传只支持\".txt\"格式的文件');history.go(-1);</script>";
        }
    }
?>
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值