PHP uploads files to the database in binary form, following code:
- <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
- <title> upload files to server-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= "file2" type= "file" id= "File2" size= "maxlength=" "></td>
- <td> </td>
- </tr>
- <tr>
- <TD height= > </td>
- <TD align= "center" ><input type= "Submission" name= "submit" value= "submitted" ></td>
- <td> </td>
- </tr>
- </form>
- <tr>
- <TD height= > </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
- if ($Submit = = "Submit") {
- $data =date ("y-m-d ");
- $file _name=" file2 ";
- $path = './upfiles/'. $_files[' File2 ' [' Name '];
- if (move_uploaded_file $_files[' file2 '] [' tmp_name '], $path)) {
- $query = "Insert into tb_file2" (File_name,file_text , data) VALUES (' $file _name ', ' $path ', ' $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;
- ? >