PHP Upload a single picture

Source: Internet
Author: User

PHP upload a single picture to the server, the following code:

 
 
  1. <?php
  2. Session_Start ();
  3. Include ("conn.php");? >
  4. <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
  5. <title> Flyer pictures to server and display-www.cxybl.com</title>
  6. <body>
  7. <table width= "355" height= "0" border= "center" align= "0" cellpadding= "0" >
  8. <tr>
  9. <TD width= "height=" > </td>
  10. <TD width= "196" > </td>
  11. <TD width= > </td>
  12. </tr>
  13. <form name= "Form1" method= "Post" action= "index_ok.php" enctype= "Multipart/form-data" >
  14. <tr>
  15. <TD height= align= "center" > </td>
  16. <TD valign= "Middle" ><input name= "Images" type= "file" id= "Images2" size= ">"
  17. <input type= "hidden" name= "max_file_size" value= "30000" > </td>
  18. <td> </td>
  19. </tr>
  20. <tr>
  21. <TD height= "> </td>"
  22. <td><input type= "Submit" name= "Submission" value= "submitted" ></td>
  23. <td> </td>
  24. </tr>
  25. </form>
  26. <tr>
  27. <TD height= "> </td>"
  28. <td> </td>
  29. <td> </td>
  30. </tr>
  31. </table>
  32. <table width= "355" border= "1" align= "center" cellpadding= "0" cellspacing= "0" >
  33. <?php $query = "SELECT * from Tb_image2 where ID order by data desc limit 2";
  34. $result =mysql_query ($query);
  35. if ($result ==true) {
  36. while ($myrow =mysql_fetch_array ($result)) {
  37. ?><tr>
  38. <TD width= "align=" "Center" ><?php Echo $myrow [data];? ></td>
  39. <TD width= "255" align= "center" > "width=" height= "></td>"
  40. </tr>
  41. <?php}}?>
  42. </table>
  43. </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. $filesize =$_files[' images '] [' size ']; 
  8. if ($filesize >1000000)  
  9.   {echo  <script> alert (' Sorry, the picture you entered is too large to upload!! ');  history.back ();</script> ";} else{ 
  10. $path  =  ' upfiles/'.  $_files[' images '] [' name ']; 
  11. if   (Move_uploaded_file ($_files[' images '] [' tmp_name '], $path))  {  
  12.       $query 1= "Insert into tb_image2 (path,data,image_name) VALUES (' $path ', ' $data ', ' $images ')"; 
  13.      $result 1=mysql_query ($query 1);  
  14.      if ($result 1=true) {   
  15.     echo  "Upload success!!";  
  16.     echo  "<meta http-equiv=\" refresh\ " content=\" 3;url= Index.php\ ">";   
  17.     }else{echo  "File upload failed!!";  
  18.           echo  <meta http-equiv =\ "refresh\"  content=\ "3;url=index.php\" ">";}  
  19. }}}&NBSP;
  20. ? > 






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.