PHP upload a single picture to the server, the following code:
- <?php
- Session_Start ();
- Include ("conn.php");? >
- <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
- <title> Flyer pictures to server and display-www.cxybl.com</title>
- <body>
- <table width= "355" height= "0" border= "center" align= "0" cellpadding= "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= "center" > </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= "> </td>"
- <td><input type= "Submit" name= "Submission" value= "submitted" ></td>
- <td> </td>
- </tr>
- </form>
- <tr>
- <TD height= "> </td>"
- <td> </td>
- <td> </td>
- </tr>
- </table>
- <table width= "355" border= "1" align= "center" cellpadding= "0" cellspacing= "0" >
- <?php $query = "SELECT * from Tb_image2 where ID order by data desc limit 2";
- $result =mysql_query ($query);
- if ($result ==true) {
- while ($myrow =mysql_fetch_array ($result)) {
- ?><tr>
- <TD width= "align=" "Center" ><?php Echo $myrow [data];? ></td>
- <TD width= "255" align= "center" > "width=" height= "></td>"
- </tr>
- <?php}}?>
- </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 ");
- $filesize =$_files[' images '] [' size '];
- if ($filesize >1000000)
- {echo <script> alert (' Sorry, the picture you entered is too large to upload!! '); history.back ();</script> ";} else{
- $path = ' upfiles/'. $_files[' images '] [' name '];
- if (Move_uploaded_file ($_files[' images '] [' tmp_name '], $path)) {
- $query 1= "Insert into tb_image2 (path,data,image_name) VALUES (' $path ', ' $data ', ' $images ')";
- $result 1=mysql_query ($query 1);
- if ($result 1=true) {
- 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;
- ? >