自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

學(xué)習(xí)筆記:PHP上傳圖片代碼詳解

開發(fā) 后端
在編程中上傳圖片是必要的,文章這里詳細(xì)的做出了關(guān)于PHP上傳圖片代碼,希望對(duì)大家有幫助。

想知道上傳圖片代碼怎么寫嗎,下面我就帶大家一起詳細(xì)分析一下吧。利用PHP,你總是可以有多種方式來(lái)完成某個(gè)特定的任務(wù)。我們就拿文件上傳舉個(gè)例子。當(dāng)然了,你可以按照傳統(tǒng)的方式來(lái)使用HTTP文件上傳,把文件直接傳輸?shù)絎eb服務(wù)器磁盤上。

#T#你還可以用更加奇異的方式上傳,用FTP協(xié)議兩步就完成上傳:從你的本地硬盤到Web服務(wù)器,然后再到FTP服務(wù)器。PHP在本機(jī)同時(shí)支持FTP和HTTP上傳,所以你可以根據(jù)自己應(yīng)用程序的設(shè)計(jì)需要進(jìn)行最佳的選擇。使用PHP的FTP函數(shù)進(jìn)行文件傳輸幾乎與使用傳統(tǒng)的FTP客戶端相同——你會(huì)看到連函數(shù)的名字都和標(biāo)準(zhǔn)的FTP命令類似。和大家分享一下PHP上傳圖片代碼的小例子,希望大家多多提意見嘿嘿謝謝了一起學(xué)習(xí)!!

PHP上傳圖片代碼:

  1. <?phpsession_start();?> 
  2.  
  3. <?php 
  4. $id=mysql_connect('localhost','root','585858');  
  5. mysql_select_db("okhwyy",$id);  
  6. mysql_query("setnamesgb2312");  
  7. ?> 
  8. <html> 
  9. <head> 
  10. <metahttp-equivmetahttp-equiv="Content-Type"c> 
  11. <title>限制上傳圖片的格式</title> 
  12. <styletypestyletype="text/css"> 
  13. <!--  
  14. .style1{  
  15. font-size:14px;  
  16. font-family:"華文行楷";  
  17. }  
  18. .style4{font-size:12px;font-weight:bold;}  
  19. --> 
  20. </style> 
  21. </head> 
  22. <body> 
  23. <tablewidthtablewidth="406"height="129"border="0"align="center"cellpadding="0"cellspacing="0"background=""> 
  24. <tr> 
  25. <tdwidthtdwidth="106"height="40"></td> 
  26. <tdwidthtdwidth="196"></td> 
  27. <tdwidthtdwidth="31"></td> 
  28. </tr> 
  29. <formnameformname="form1"method="post"action=""enctype="multipart/form-data"> 
  30. <tr> 
  31. <tdheighttdheight="32"align="right"><spanclassspanclass="style1">圖片路徑</span>:</td> 
  32. <tdvaligntdvalign="middle"><inputnameinputname="images"type="file"id="images2"size="15"> 
  33. <inputtypeinputtype="hidden"name="MAX_FILE_SIZE"value="30000"></td> 
  34. <td></td> 
  35. </tr> 
  36. <tr> 
  37. <tdheighttdheight="44"align="right"valign="middle"><spanclassspanclass="style4">圖片的格式</span>:</td> 
  38. <tdvaligntdvalign="middle"><spanclassspanclass="style4">(.jpg)</span><inputtypeinputtype="submit"name="Submit"value="提交"></td> 
  39. <td></td> 
  40. </tr> 
  41. </form> 
  42. <tr> 
  43. <tdheighttdheight="10"></td> 
  44. <td></td> 
  45. <td></td> 
  46. </tr> 
  47. </table> 
  48. <tablewidthtablewidth="406"height="129"border="1"align="center"cellpadding="0"cellspacing="0"> 
  49. <?php 
  50. $query="select*fromtb_image2whereidorderbydatadesclimit2";  
  51. $result=mysql_query($query);  
  52. if($result){  
  53. while($row=mysql_fetch_array($result)){  
  54. ?> 
  55. <tr> 
  56. <tdwidthtdwidth="106"align="center"><?phpecho$row[data];?></td> 
  57. <tdwidthtdwidth="196"align="center"><imgsrcimgsrc="<?phpecho$row[path];?>"width="200"height="120"></td> 
  58. </tr> 
  59. <?php}}?> 
  60. </table> 
  61.  
  62. </body> 
  63. </html> 
  64.  
  65. <?php 
  66. $Submit=$_POST[Submit];  
  67. if($Submit){  
  68. $image=$_FILES['images']['name'];  
  69. $datedate=date("Y-m-d");  
  70. $path="upfiles/".$_FILES['images']['name'];  
  71. $type=strstr($path,".");  
  72. $size=$_FILES['images']['size'];  
  73. if($size>1000000){echo"<script>alert('上傳容量超限');history.back();</script>";}  
  74. elseif($type!=".jpg"){echo"<script>alert('上傳類型不對(duì)');history.back();</script>";}  
  75. elseif(move_uploaded_file($_FILES['images']['tmp_name'],$path)){  
  76. $query="insertintotb_image2(image_name,path,data)values('$image','$path','$date')";  
  77. $result=mysql_query($query)ordie(mysql_error());  
  78. if($result){  
  79. echo"上傳成功!";  
  80. echo"<metahttp-equivmetahttp-equiv=&#92;\"Refresh&#92;\"content=&#92;\"3;url=index.php&#92;\">";  
  81. }  
  82. else{  
  83. echo"上傳失敗!";  
  84. echo"<metahttp-equivmetahttp-equiv=&#92;\"Refresh&#92;\"content=&#92;\"3;url=index.php&#92;\">";  
  85. }}}  
  86.  
  87. ?> 
責(zé)任編輯:田樹 來(lái)源: 博客
相關(guān)推薦

2009-11-16 14:38:36

PHP上傳文件代碼

2009-11-16 11:18:38

PHP上傳圖片代碼

2009-11-16 13:27:20

PHP上傳多張圖片

2009-11-30 19:09:46

PHP上傳圖片

2009-11-16 10:49:43

PHP上傳文件代碼

2009-11-16 10:40:02

PHP上傳文件代碼

2009-11-24 14:45:08

PHP批量上傳圖片

2022-01-18 08:12:02

Markdown編輯器拍云

2011-04-19 10:32:28

圖片數(shù)據(jù)庫(kù)

2009-11-17 17:17:50

PHP上傳多個(gè)文件

2010-06-03 11:12:55

Hadoop

2009-11-16 10:57:51

PHP上傳文件代碼

2009-12-07 15:41:51

PHP圖片加水印

2009-11-24 16:09:44

PHP Ajax

2010-08-26 16:40:35

DIV定位

2011-07-26 15:29:36

Cocoa 模式

2010-06-29 13:22:26

UML類圖

2010-07-06 11:07:11

UML組件圖

2010-08-31 11:25:15

2011-09-07 10:34:48

Android Wid
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)