background image

//

 

简要说明

上传界面,用户选择文件,然后提交给 submit.php

 

处理

 

值得注意的是一个 MAX_FILE_SIZE 的隐藏值域,通过设置其 VALUE

  

 

以限制上载文件的大小。
//

 

程序源码

<html>   
<head>   
<title>文件上传表单</title>   
</head>   
<body>   
<table>   
<form enctype='multipart/form-data' name='myform' action='submit.php'  
method='post'>   
<INPUT TYPE = "hidden" NAME = "MAX_FILE_SIZE" VALUE ="1000000"> 
<tr><td>选择上传文件</td><td> 
<input name='myfile' type='file'></td></tr>  
<tr><td colspan='2'><input name='submit' value='上传'   
type='submit'></td></tr>   
</table>   
</body>   
</html> 

////////////////////////////////////////////////////////////////////// 
(3)submit.php --- 
//

 

简要说明

 

把用户上传得文件连同文件的基本信息保存到数据库里
//

 

程序源码

<?php   
    if($myfile != "none" && $myfile != "") { //

  

有了上传文件了

        //设置超时限制时间,

 

缺省时间为 30 秒,设置为 0

 

时为不限时

        $time_limit=60;          
        set_time_limit($time_limit); // 

        //

 

把文件内容读到字符串中

        $fp=fopen($myfile,  "rb"); 
        if(!$fp) die("file open error"); 
        $file_data = addslashes(fread($fp, filesize($myfile))); 
        fclose($fp); 
        unlink($myfile);  
             
        //文件格式,名字,

 

大小

        $file_type=$myfile_type; 
        $file_name=$myfile_name;