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

首頁 > 語言 > PHP > 正文

一款簡單PHP圖片上傳類帶圖片顯示代碼

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

這是一款簡單PHP圖片上傳類帶圖片顯示代碼,應該可以說是上傳文件最簡單的上傳類了,可以設置要顯示圖片高度與寬度,文件大小等.

uploadimg.class.php文件,代碼如下:

  1. class upload  
  2. {  
  3. var $upload_name;  
  4. var $upload_tmp_address;  
  5. var $upload_server_name;  
  6. var $upload_filetype ;  
  7. var $file_type;  
  8. var $file_server_address;  
  9. var $image_w=900; //要顯示圖片的寬  
  10. var $image_h=350; //要顯示圖片的高  
  11. var $upload_file_size;  
  12. var $upload_must_size= 50000; //允許上傳文件的大小,自己設置  
  13. function upload_file()  
  14. {  
  15. $this->upload_name = $_files["file"]["name"]; //取得上傳文件名  
  16. $this->upload_filetype = $_files["file"]["type"];  
  17. $this->upload_server_name = date("y_m_dh_i_s").$this->upload_name;  
  18. $this->upload_tmp_address = $_files["file"]["tmp_name"]; //取得臨時地址  
  19. $this->file_type = array("image/gif","image/pjpeg"); //允許上傳文件的類型  
  20. $this->upload_file_size = $_files["file"]["size"]; //上傳文件的大小  
  21. if(in_array($this->upload_filetype,$this->file_type))  
  22. if($this->upload_file_size < $this->upload_must_size)  
  23. {  
  24. echo("上傳成功,謝謝支持");  
  25. $this->file_server_address = "d:www.111cn.netupload/".$this->upload_server_name;  
  26. move_uploaded_file($this->upload_tmp_address,$this->file_server_address);//從temp目錄移出  
  27. echo("<img src=$this->file_server_address width=$this->image_w height=$this->image_h/>"); //顯示圖片 
  28.  
  29.  
  30. }  
  31. else  
  32. {  
  33. echo("文件容量太大");  
  34. }  
  35. }  
  36. else  
  37. {  
  38. echo("不支持此文件類型,請重新選擇");  
  39. //開源代碼Vevb.com 
  40.  
  41.  

html上傳代碼,代碼如下:

  1. <form id="form1" name="upload" enctype="multipart/form-data" method="post" action="upload.php">  
  2. <input type="hidden" name="max_file_size " />  
  3. <input type="file" name="file" />  
  4. <input type="submit" name="submit" value="提交" />  
  5. </form> 

調用方法,upload.php,代碼如下:

  1. inlcude('uploadimg.class.php'); 
  2. $dd = new upload;  
  3. $dd->upload_file();

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 斗六市| 珠海市| 漳浦县| 大名县| 民和| 左权县| 密山市| 武城县| 阳谷县| 昂仁县| 马山县| 化德县| 钦州市| 玛多县| 岐山县| 安吉县| 德阳市| 麦盖提县| 右玉县| 陇川县| 延川县| 元江| 定州市| 宜川县| 乐山市| 周宁县| 萝北县| 娱乐| 镇雄县| 高雄县| 慈溪市| 尼木县| 赤城县| 滁州市| 祁连县| 温州市| 旅游| 三河市| 南郑县| 莱芜市| 霍邱县|