PHP limits the format of the image upload, the following code:
- <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
- <title> limit the format of uploaded images-www.cxybl.com</title>
- <style type= "Text/css" >
- <!--
- . style1 {
- font-size:14px;
- Font-family: "XXFarEastFont-Xingkai";
- }
- . style4 {font-size:12px; font-weight:bold;}
- -->
- </style>
- <body>
- <table width= "406" height= "129" border= "0" align= "center" cellpadding= "0" cellspacing= "0" >
- <tr>
- <TD width= "height=" > </td>
- <TD width= "196" > </td>
- <TD width= > </td>
- </tr>
- <form name= "Form1" method= "Post" action= "index_ok.php" enctype= "Multipart/form-data" >
- <tr>
- <TD height= "align=" "right" ><span class= "style1" > Picture path </span>:</td>
- <TD valign= "Middle" ><input name= "Images" type= "file" id= "Images2" size= ">"
- <input type= "hidden" name= "max_file_size" value= "30000" > </td>
- <td> </td>
- </tr>
- <tr>
- <TD height= "align=" "right" valign= "middle" ><span class= "style4" > Picture format </span>:</td>
- <TD valign= "Middle" ><span class= "Style4" > (. jpg) </span>
- <input type= "Submit" name= "Submission" value= "submitted" ></td>
- <td> </td>
- </tr>
- </form>
- <tr>
- <TD height= "Ten" > </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 ");
- $path = ' upfiles/'. $_files[' images '] [' name '];
- $ Type=strstr ($path, '. ');
- if ($type!= ". jpg") {echo "<script> alert" (' Sorry, the format of the picture you uploaded is not!! '); history.back ();</script> ";
- }else{
- if (move_uploaded_ File ($_files[' images '] [' tmp_name '], $path)) {
- $query 1= "Insert into tb_image2 (Path,data,image_name) VALUES (' $path ', ' $data ', ' $images ');
-
- if ($result 1=true) {
- &Nbsp; echo "Upload success!!";
- echo "<meta http-equiv=\" refresh\ " content=\" 3;url= Index.php\ ">";
- }else{echo "File upload failed!!";
- echo <meta http-equiv =\ "refresh\" content=\ "3;url=index.php\" ">";}
- }}}&NBSP;
- ? >