国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php 圖片上傳代碼例子

2024-09-04 11:44:59
字體:
來源:轉載
供稿:網友

下面來為你免費提供一款php 圖片上傳代碼,如果你正在找文件上傳的圖片代碼就進來看看吧,這是一款只支持jpg,gif,png,swf文件上傳的php實例代碼.

PHP實例代碼如下:

  1. <?php  
  2. if($_FILES['file']){ 
  3.  
  4.  // 上傳設置 
  5.  $maxsize=10002400;            //最大允許上傳的文件大小 
  6.  $alltype=array(".jpg",".JPG",".GIF",".gif",".png",".swf");         //所有允許上傳的文件類型 
  7.  $imgtype=array(".jpg",".JPG",".GIF",".gif",".png",".swf");               //圖片類型 
  8.  
  9.  // 判斷文件大小 
  10.  if($_FILES['file']['size']>$maxsize)  { 
  11.      echo "您上傳的資料大于10000K"
  12.      exit
  13.  } 
  14.   
  15.  // 判斷文件類型 
  16.  $type=strstr($_FILES['file']['name'],"."); 
  17.  if(!in_array($type,$alltype)){ 
  18.      echo "不允許上傳該類型的文件"
  19.      exit
  20.  } 
  21.  $updir="uploaddir"
  22.  $time=date("Ymd-His",time()); 
  23.  $fn=$time.$type
  24.  $destination=$updir."/".$fn
  25.  if(@move_uploaded_file($_FILES['file']['tmp_name'], $destination)){ 
  26.          @chmod($destination, 0777); 
  27.    $fileurl=$updir."/".$destination
  28.          $fileurl="".$destination
  29.             
  30.  }else
  31.     echo "上傳失敗!"
  32.     echo "<script>location.href=history.back()</script>"
  33.  } 
  34. // ----------------------------------------------------------------------------------------------// 
  35. }//開源代碼Vevb.com 
  36. if($back=="no"): 
  37.  echo "ok"
  38.  exit
  39. endif
  40. ?> 

html代碼如下:

  1. <html> 
  2. <head> 
  3. <title>添加圖片</title> 
  4. <script language="JavaScript"> 
  5. function isnull() 
  6.          if(document.all.fileurl.value!="")insert(); 
  7. function insert() 
  8.         images='<img style="cursor:hand" src="'+insertpic.fileurl.value+'">'; 
  9.         edit = window.opener.document.mode_iframe.document.selection.createRange(); 
  10.         edit.pasteHTML (images); 
  11.         window.close(); 
  12. </script> 
  13. <style> 
  14. BODY {        FONT-SIZE: 12px; FONT-FAMILY: tahoma,宋體;} 
  15. TABLE {        empty-cells: show;} 
  16. TD {        FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: tahoma,宋體;margin: 5} 
  17. </style> 
  18. </head> 
  19. <body leftMargin=12 topMargin=12 marginwidth=2 marginheight=2 bgcolor='#D6D3CE' style="border:0px" onload=isnull()> 
  20. <form action=<?=$_SERVER['PHP_SELF']?> name=insertpic enctype=multipart/form-data method=post> 
  21. <table> 
  22. <tr> 
  23.         <td></td> 
  24.         <td width=60>上傳圖片</td> 
  25.         <td> 
  26.   <input class=mmcinb type="file" name="file" size="14"> 
  27.         <input class=mmcinb type="submit" value="上傳"></td> 
  28. </tr> 
  29. <tr> 
  30.         <td></td> 
  31.         <td>圖片URL</td> 
  32.         <td><input class=mmcinb type="text" name="fileurl" value="<?=$fileurl?>" size="26"> 
  33.         <button onclick=insert()>插入</button></td> 
  34. </tr> 
  35. <tr> 
  36.         <td></td> 
  37.          
  38.       <td colspan=2 align=left><font color=red>可以直接輸入圖片的URL,點擊插入即可(不能有中文)<br> 
  39.         </font></td> 
  40. </tr> 
  41. </table> 
  42. </form> 
  43. <script language="JavaScript"> 
  44. <!-- 
  45.         //picurl.focus(); 
  46. //--> 
  47. </script> 
  48. </body> 
  49. </html> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新河县| 景德镇市| 岳阳市| 斗六市| 牡丹江市| 育儿| 张家界市| 贺州市| 闽清县| 武功县| 湘潭县| 文登市| 娄烦县| 防城港市| 五台县| 光山县| 泰兴市| 彝良县| 蒙阴县| 大关县| 修文县| 朝阳区| 高陵县| 江北区| 昌邑市| 松潘县| 扬中市| 蕲春县| 隆林| 许昌县| 桑日县| 镇赉县| 罗定市| 永登县| 岱山县| 体育| 玛纳斯县| 吉隆县| 宝山区| 高安市| 绵竹市|