PHP restricts image Upload format

Source: Internet
Author: User
Tags file upload query

PHP limits the format of the image upload, the following code:

 
 
  1. <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
  2. <title> limit the format of uploaded images-www.cxybl.com</title>
  3. <style type= "Text/css" >
  4. <!--
  5. . style1 {
  6. font-size:14px;
  7. Font-family: "XXFarEastFont-Xingkai";
  8. }
  9. . style4 {font-size:12px; font-weight:bold;}
  10. -->
  11. </style>
  12. <body>
  13. <table width= "406" height= "129" border= "0" align= "center" cellpadding= "0" cellspacing= "0" >
  14. <tr>
  15. <TD width= "height=" > </td>
  16. <TD width= "196" > </td>
  17. <TD width= > </td>
  18. </tr>
  19. <form name= "Form1" method= "Post" action= "index_ok.php" enctype= "Multipart/form-data" >
  20. <tr>
  21. <TD height= "align=" "right" ><span class= "style1" > Picture path </span>:</td>
  22. <TD valign= "Middle" ><input name= "Images" type= "file" id= "Images2" size= ">"
  23. <input type= "hidden" name= "max_file_size" value= "30000" > </td>
  24. <td> </td>
  25. </tr>
  26. <tr>
  27. <TD height= "align=" "right" valign= "middle" ><span class= "style4" > Picture format </span>:</td>
  28. <TD valign= "Middle" ><span class= "Style4" > (. jpg) </span>
  29. <input type= "Submit" name= "Submission" value= "submitted" ></td>
  30. <td> </td>
  31. </tr>
  32. </form>
  33. <tr>
  34. <TD height= "Ten" > </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. $path  =  ' upfiles/'.  $_files[' images '] [' name ']; 
  8. $ Type=strstr ($path, '. ');  
  9. if ($type!= ". jpg") {echo  "<script> alert" (' Sorry, the format of the picture you uploaded is not!! ');  history.back ();</script> ";  
  10. }else{ 
  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.     if ($result 1=true) {  
  14. &Nbsp;   echo  "Upload success!!";  
  15.     echo  "<meta http-equiv=\" refresh\ " content=\" 3;url= Index.php\ ">";   
  16.     }else{echo  "File upload failed!!";  
  17.           echo  <meta http-equiv =\ "refresh\"  content=\ "3;url=index.php\" ">";}  
  18. }}}&NBSP;
  19. ? > 






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.