Practice one: User registration lead like
Show Page
<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">"Content-type"Content="text/html; Charset=utf-8"/><title> Untitled Document </title>"chuli.php"Method="Post"Enctype="Multipart/form-data"><div> User <input Type="text"Name="UID"/></div><div> Password <input type="text"Name="pwd"/></div><div> name <input type="text"Name="name"/></div><div> Sex <input type="text"Name="Sex"/></div><div> Birthday <input type="text"Name="Birthday"/></div><div> Head <input type="file"Name="pic"/></div><input type="Submit"Value="Register"/></form></body>Working with pages
<?Phpvar_dump ($_files["pic"]); Include (".. /dbda.class.php"); $db=NewDbda ();//control upload format and sizeif(($_files["pic"]["type"]=="Image/jpeg"|| $_files["pic"]["type"]=="Image/png") && $_files["pic"]["size"]<=100000){ //working with file names$filename ="./img/". Time (). $_files["pic"]["name"]; //transcoding format$filename =iconv ("UTF-8","gb2312", $filename); //determine if a file exists if(!file_exists ($filename)) { //Upload (Save)Move_uploaded_file ($_files["pic"]["Tmp_name"], $filename); }}//add a piece of data to the table user$uid =$_post["UID"]; $pwd=$_post["pwd"]; $name=$_post["name"]; $sex=$_post["Sex"]; $birthday=$_post["Birthday"]; $url="/lianxi/wenjianshangchuan/". $filename; $sql="Insert User values (' ', ' {$uid} ', ' {$pwd} ', ' {$name} ', ' {$sex} ', ' {$birthday} ', ' {$url} ')"; $result= $db->query ($sql,0);if($result) {header ("loaction:login.php");}Else{echo"Add failed";}
Exercise two: File download<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"http://www.w3.org/1999/xhtml">"Content-type"Content="text/html; Charset=utf-8"/><title> untitled document </TITLE></HEAD><BODY><?Phpinclude (".. /dbda.class.php"); $db=NewDbda (); $sql="SELECT * from user"; $attr= $dbQuery ($sql);? ><table border="1"><tr><td> uploader </td><td> Upload time </td><td> file name </td><td> actions </td> </tr><?PHPforeach($attr as$v) {echo"<tr> <td>{$v [1]}</td> <td>{$v [5]}</td> <td>{$v [3]}</td> <td><a href='{$v [6]}'> Downloads </a></td> </tr>"; }?>
File Upload Exercise