PHP限制圖片上傳的格式

來源:互聯網
上載者:User

PHP限制圖片上傳的格式,如下代碼:

 
  1. <html> 
  2. <head> 
  3. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
  4. <title>限制上傳圖片的格式 - www.cxybl.com</title> 
  5. <style type="text/css"> 
  6. <!-- 
  7. .style1 { 
  8.     font-size: 14px; 
  9.     font-family: "華文行楷"; 
  10. .style4 {font-size: 12px; font-weight: bold; } 
  11. --> 
  12. </style> 
  13. </head> 
  14.  
  15. <body> 
  16. <table width="406" height="129" border="0" align="center" cellpadding="0" cellspacing="0"> 
  17.   <tr> 
  18.     <td width="106" height="40"> </td> 
  19.     <td width="196"> </td> 
  20.     <td width="31"> </td> 
  21.   </tr> 
  22. <form name="form1" method="post" action="index_ok.php" enctype="multipart/form-data"> 
  23.   <tr> 
  24.     <td height="32" align="right"><span class="style1">圖片路徑</span>:</td> 
  25.     <td valign="middle"><input name="images" type="file" id="images2" size="15"> 
  26.      <input type="hidden" name="MAX_FILE_SIZE" value="30000">   </td> 
  27.     <td> </td> 
  28.   </tr> 
  29.   <tr> 
  30.     <td height="44" align="right" valign="middle"><span class="style4">圖片的格式</span>:</td> 
  31.     <td valign="middle"><span class="style4">(.jpg)</span>       
  32. <input type="submit" name="Submit" value="提交"></td> 
  33.     <td> </td> 
  34.   </tr> 
  35.  </form> 
  36.   <tr> 
  37.     <td height="10"> </td> 
  38.     <td> </td> 
  39.     <td> </td> 
  40.   </tr> 
  41. </table> 
  42. </body> 
  43. </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. $path = 'upfiles/'. $_FILES['images']['name']; 
  8. $type=strstr($path,'.'); 
  9. if($type!=".jpg"){echo "<script> alert('對不起,您上傳的圖片的格式不對!!'); history.back();</script>"; 
  10. }else{ 
  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.