PHP uploads files to database in binary form

Source: Internet
Author: User
Tags file upload query

PHP uploads files to the database in binary form, following code:

 
 
  1. <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
  2. <title> upload files to server-www.cxybl.com</title>
  3. <style type= "Text/css" >
  4. <!--
  5. Body {
  6. margin-left:00px;
  7. margin-top:0px;
  8. margin-right:0px;
  9. margin-bottom:0px;
  10. }
  11. -->
  12. </style>
  13. <body>
  14. <table width= "385" height= "185" border= "0" cellpadding= "0" cellspacing= "0" >
  15. <tr>
  16. <TD width= "130" height= "> </td>"
  17. <TD width= > </td>
  18. <TD width= "> </td>"
  19. </tr>
  20. <form name= "Form1" method= "Post" action= "index_ok.php" enctype= "Multipart/form-data" >
  21. <tr>
  22. <TD height= > </td>
  23. <TD align= "center" valign= "Middle" >
  24. <input name= "file2" type= "file" id= "File2" size= "maxlength=" "></td>
  25. <td> </td>
  26. </tr>
  27. <tr>
  28. <TD height= > </td>
  29. <TD align= "center" ><input type= "Submission" name= "submit" value= "submitted" ></td>
  30. <td> </td>
  31. </tr>
  32. </form>
  33. <tr>
  34. <TD height= > </td>
  35. <td> </td>
  36. <td> </td>
  37. </tr>
  38. </table>
  39. </body>

conn.php:

 
  
  
  1. <?php
  2. $id =mysql_connect (' localhost ', ' root ', ' root ');
  3. mysql_select_db ("Db_database12", $id);
  4. mysql_query ("Set names gb2312");
  5. ?>

index_ok.php:

 
  
  
  1. <?PHP&NBSP;&NBSP;
  2. session_start ();   
  3. include" ("conn.php");? > 
  4. <?php 
  5.  if ($Submit = = "Submit") { 
  6. $data =date ("y-m-d ");  
  7. $file _name=" file2 ";  
  8. $path  =  './upfiles/'.  $_files[' File2 ' [' Name ']; 
  9. if  (move_uploaded_file $_files[' file2 '] [' tmp_name '], $path))  {  
  10.      $query = "Insert into tb_file2" (File_name,file_text , data) VALUES (' $file _name ', ' $path ', ' $data ');  
  11.      $result =mysql_ Query ($query);  
  12.     if ($result =true) {  
  13.      echo  "Upload success!!";  
  14.     echo  "<meta http-equiv=\" refresh\ " content=\" 3;url= index.php?lmbs= File Upload\ >   
  15.     }else{echo  "File upload failed!!";  
  16.           echo  <meta http-equiv =\ "refresh\"  content=\ 3;url=index.php?lmbs= file upload \ ">";}  
  17. }}&NBSP;
  18. ? > 






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.