PHP上傳單張圖片

來源:互聯網
上載者:User

PHP上傳單張圖片到伺服器,如下代碼:

 
  1. <?php  
  2. session_start();  
  3. include("conn.php");?> 
  4. <html> 
  5. <head> 
  6. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
  7. <title>上傳單圖片到伺服器並顯示 - www.cxybl.com</title> 
  8. </head> 
  9.  
  10. <body> 
  11. <table width="355" height="240" border="0" align="center" cellpadding="0" cellspacing="0"> 
  12.   <tr> 
  13.     <td width="106" height="100"> </td> 
  14.     <td width="196"> </td> 
  15.     <td width="31"> </td> 
  16.   </tr> 
  17. <form name="form1" method="post" action="index_ok.php" enctype="multipart/form-data"> 
  18.   <tr> 
  19.     <td height="30" align="center"> </td> 
  20.     <td valign="middle"><input name="images" type="file" id="images2" size="15"> 
  21.      <input type="hidden" name="MAX_FILE_SIZE" value="30000">   </td> 
  22.     <td> </td> 
  23.   </tr> 
  24.   <tr> 
  25.     <td height="55"> </td> 
  26.     <td><input type="submit" name="Submit" value="提交"></td> 
  27.     <td> </td> 
  28.   </tr> 
  29.  </form> 
  30.   <tr> 
  31.     <td height="55"> </td> 
  32.     <td> </td> 
  33.     <td> </td> 
  34.   </tr> 
  35. </table> 
  36. <table width="355" border="1" align="center" cellpadding="0" cellspacing="0"> 
  37.  <?php $query="select * from tb_image2 where id order by data desc limit 2"; 
  38.  $result=mysql_query($query); 
  39.  if($result==true){ 
  40.  while($myrow=mysql_fetch_array($result)){  
  41.  ?><tr> 
  42.     <td width="100" align="center"><?php echo $myrow[data];?></td> 
  43.     <td width="255" align="center"><img src="<?php echo $myrow[path];?>" width="200" height="150"></td> 
  44.   </tr> 
  45.   <?php }}?> 
  46. </table> 
  47. </body> 
  48. </html> 

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  
  2. session_start();  
  3. include("conn.php");?> 
  4. <?php 
  5.  if($Submit=="提交"){ 
  6. $data=date("Y-m-d"); 
  7. $filesize=$_FILES['images']['size']; 
  8. if($filesize>1000000) 
  9.   {echo "<script> alert('對不起,您輸入的圖片太大,不能上傳!!'); history.back();</script>";}else{ 
  10. $path = 'upfiles/'. $_FILES['images']['name']; 
  11. if (move_uploaded_file($_FILES['images']['tmp_name'],$path)) {  
  12.     $query1="insert into tb_image2(path,data,image_name)values('$path','$data','$images')"; 
  13.     $result1=mysql_query($query1); 
  14.     if($result1=true){  
  15.     echo "上傳成功!!"; 
  16.     echo "<meta http-equiv=\"Refresh\" content=\"3;url=index.php\">";  
  17.     }else{echo "檔案上傳失敗!!"; 
  18.           echo "<meta http-equiv=\"Refresh\" content=\"3;url=index.php\">";} 
  19. }}} 
  20. ?> 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.