PHP? ??? MySql ??????? ??? ?? ???(4)
?? ????? ?? ?? ??? ?? ??? ???? ? ?? ??? ???? ??? ??????.
??? ?? ?? ??? ??? ????? ??? ?? ??? ???? ???.
include_once ?? ???? ???.
include_once ? ???? ?? ?? ??? ??? ???? ?????. ? ??? include ?? ?????. ??? ???? ??? ?? ??? ?? ?? ???? ???? ????. ? ???? ???? ? ? ??? ? ?? ?????. include_once? ???? ?? ?? ??? ??? ? ? ?? ??? ? ??? ?? ??? ? ?? ???? ?? ??? ??? ?? ? ?? ????? ??? ?? ??? ? ????. ?? ???? upload.php ??? ??????<?php include_once('upload.php'); ?>
??? ?? ?? ?????.
<?php header("content-type:text/html;charset=utf8"); $link = mysqli_connect('localhost','username','password','test'); mysqli_set_charset($link, "utf8"); if (!$link) { die("連接失敗:".mysqli_connect_error()); } $action = isset($_GET['action'])?$_GET['action']:""; if ($action == "save"){ include_once('uploadclass.php'); //引入外部文件 $title = $_POST['title']; $pic = $uploadfile; if($title == "") //判斷是否在標(biāo)題中添加內(nèi)容 echo"<Script>window.alert('對不起!你輸入的信息不完整!');history.back()</Script>"; $sql = "insert into img(title,pic) values('$title','$pic')"; //向數(shù)據(jù)庫中添加文件內(nèi)容 $result = mysqli_query($link,$sql); } ?> <html> <head> <meta charset="utf-8"> <title>文件上傳實例</title> <style type="text/css"> <!-- body { font-size: 20px; } input { background-color: #66CCFF; border: 1px inset #CCCCCC; } form { margin-top:5%; } --> </style> </head> <body> <form method="post" action="?action=save" enctype="multipart/form-data"> <table border=0 cellspacing=0 cellpadding=0 align=center width="100%"> <tr> <td width=55 height=20 align="center"></td> <td height="16"> <table> <tr> <td>標(biāo)題:</td> <td><input name="title" type="text" id="title"></td> </tr> <tr> <td>文件: </td> <td><label> <input name="file" type="file" value="瀏覽" > <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> </label></td> </tr> <tr> <td></td> <td><input type="submit" value="上 傳" name="upload"></td> </tr> </table> </td> </tr> </table> </form> </body> </html>