PHP limit File upload type, the following code:
- <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
- <title> limit the types of uploaded files-www.cxybl.com</title>
- <style type= "Text/css" >
- <!--
- Body {
- margin-left:00px;
- margin-top:0px;
- margin-right:0px;
- margin-bottom:0px;
- }
- -->
- </style>
- <body>
- <table width= "385" height= "185" border= "0" cellpadding= "0" cellspacing= "0" >
- <tr>
- <TD width= "130" height= "> </td>"
- <TD width= > </td>
- <TD width= "> </td>"
- </tr>
- <form name= "Form1" method= "Post" action= "index_ok.php" enctype= "Multipart/form-data" >
- <tr>
- <TD height= "> </td>"
- <TD align= "center" valign= "Middle" >
- <input name= "file4" type= "file" id= "File4" size= "maxlength=" "></td>
- <td> </td>
- </tr>
- <tr>
- <TD height= "align=" "Right" > </td>
- <TD align= "center" valign= "top" ><input type= "Submit" name= "Submission" value= "submitted" > </td>
- <td> </td>
- </tr>
- </form>
- <tr>
- <TD height= "a" > </td>
- <td> </td>
- <td> </td>
- </tr>
- </table>
- </body>
conn.php:
- <?php
- $id =mysql_connect (' localhost ', ' root ', ' root ');
- mysql_select_db ("Db_database12", $id);
- mysql_query ("Set names gb2312");
- ?>
index_ok.php:
- <?PHP&NBSP;&NBSP;
- session_start ();
- include" ("conn.php");
- ? >
- <?PHP&NBSP;
- if ($ submit== "Submit") {
- $data =date ("y-m-d");
- $file _name= "files"; // Name the upload file
- $name =$_files[' file4 '] [' name ']; //get the names of the client machine's original files
- $type = Strstr ($name, "."); //gets the from "." To the last character
- if ($type!= ". txt") {
- echo "Sorry, the format of your uploaded file is incorrect!!";
- echo "<meta http-equiv=\" refresh\ " content=\" 3;url=index.php?lmbs = File upload \ > will return to front page after 3 seconds ...;
- }else{
- $query = " Insert into tb_file1 (File_name,file_text,data) VALUES (' $file _name ', ' $file 4 ', ' $data ') ";
- $result =mysql_query ($query);
- if ($result =true) {
- echo "Upload success!!";
- echo <meta http-equiv=\ "Refresh\" content=\ "3;url=index.php?lmbs= file upload \ >";
- }else{echo File upload failed!! ";
- echo <meta http-equiv=\ "refresh\" content=\ 3;url=index.php?lmbs= file upload \ ">";}
- }}
- ?>&NBSP;