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

首頁(yè) > 語(yǔ)言 > PHP > 正文

php文件圖片上傳類(lèi)

2024-09-04 11:45:05
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這款文件上傳實(shí)用代碼,可以方便的上傳你指定的文件或圖片,同時(shí)也可以快速的限制上傳圖片文件類(lèi)或大小,實(shí)例代碼如下:

  1. /* 
  2.  * created on 2010-6-21 
  3.  * 
  4.  * the class for image to upload 
  5.  * 
  6.  * made by s71ence 
  7.  * 
  8.  * @$user_id 
  9.  * @$max_file_size 
  10.  * @$max_image_side 
  11.  * @$destination_folder 
  12.  * 
  13.  * return: 
  14.  * @$_cookie['img_path'] 
  15.  * @$img_unfind 
  16.  * @$img_type 
  17.  * @$mkdir_warry 
  18.  * @$img_side_too_big 
  19.  * @$img_exist 
  20.  * @$img_move 
  21.  * @$img_upload_sucess 
  22.  */ 
  23.  
  24.  
  25.  代碼如下 復(fù)制代碼  
  26. header('content-type:text/html;charset=utf-8'); 
  27.  
  28.  class image_upload extends fn_function 
  29.  { 
  30.  private $user_id
  31.  private $max_file_size//allow the image's size 
  32.  private $max_image_side//allow the image's side 
  33.  private $destination_folder//image's storage path 
  34.  private $img_preview
  35.  private $img_preview_size
  36.  private $cookie_set//the cookie's name 
  37.  
  38.  function __construct($user_id,$max_file_size,$max_image_side,$destination_folder,$img_preview,$img_preview_size,$cookie_set
  39.  { 
  40.   $this->user_id=$user_id
  41.   $this->max_file_size=$max_file_size
  42.   $this->max_image_side=$max_image_side
  43.   $this->destination_folder=$destination_folder
  44.   $this->img_preview=$img_preview
  45.   $this->img_preview_size=$img_preview_size
  46.   $this->cookie_set=$cookie_set
  47.   $this->get_date(); 
  48.   $this->get_image_type(); 
  49.  } 
  50.  
  51.  private function get_date() 
  52.  { 
  53.   $this->date=fn_function::get_server_date(); 
  54.   return $this->date
  55.  } 
  56.  
  57.  function get_image_type() 
  58.  { 
  59.   $this->up_img_types=array
  60.             'image/jpg'
  61.             'image/jpeg'
  62.             'image/png'
  63.             'image/pjpeg'
  64.             'image/gif'
  65.             'image/bmp'
  66.             'image/x-png' 
  67.         ); 
  68.  
  69.   return $this->up_img_types; 
  70.  } 
  71.  
  72.  function upload_image() 
  73.  { 
  74.   if ($_server['request_method'] == 'post'
  75.   { 
  76.    //check the iamge is exist 
  77.    if (!is_uploaded_file($_files["upfile"]["tmp_name"])) 
  78.    { 
  79.     return $img_unfind=fn_function::alert_msg('圖片不存在!'); 
  80.     exit
  81.       } 
  82.  
  83.       $file = $_files["upfile"]; 
  84.  
  85.    //check the iamge's size 
  86.       if($this->max_file_size < $file["size"]) 
  87.       { 
  88.        return $img_side_too_big=fn_function::alert_msg('圖片大小超過(guò)系統(tǒng)允許最大值!'); 
  89.        exit
  90.       } 
  91.  
  92.       //check the iamge's type 
  93.       if(!in_array($file["type"], $this->up_img_types)) 
  94.       { 
  95.        return $img_type=fn_function::alert_msg('圖片類(lèi)型不符!'); 
  96.        exit
  97.       } 
  98.  
  99.       if(!file_exists($this->destination_folder)) 
  100.       { 
  101.        if(!fn_function::mkdirs($this->destination_folder)) 
  102.        { 
  103.         return $mkdir_warry=fn_function::alert_msg('目錄創(chuàng)建失敗!'); 
  104.         exit
  105.        } 
  106.       } 
  107.  
  108.       $file_name=$file["tmp_name"]; 
  109.       $image_size = getimagesize($file_name); 
  110.       $pinfo=pathinfo($file["name"]); 
  111.       $file_type=$pinfo['extension']; 
  112.       $destination = $this->destination_folder.time().".".$file_type
  113.    setcookie($this->cookie_set, $destination); 
  114.  
  115.    if($image_size[0]>$this->max_image_side || $image_size[1]>$this->max_image_side) 
  116.    { 
  117.     return $img_side_too_big=fn_function::alert_msg('圖片分辨率超過(guò)系統(tǒng)允許最大值!'); 
  118.     exit
  119.    } 
  120.  
  121.    $overwrite=""
  122.    if (file_exists($destination) && $overwrite != true) 
  123.    { 
  124.     return $img_exist=fn_function::alert_msg('同名文件已經(jīng)存在了!'); 
  125.     exit
  126.       } 
  127.  
  128.       if(!move_uploaded_file ($file_name$destination)) 
  129.       { 
  130.        return $img_move=fn_function::alert_msg('移動(dòng)文件出錯(cuò)!'); 
  131.        exit
  132.       } 
  133.  
  134.    $img_upload_sucess="<font color=red face=微軟雅黑>上傳成功</font><br>"
  135.    if($this->img_preview==1) 
  136.    { 
  137.     $img_src="<img src="".$destination."" width=".($image_size[0]*$this->img_preview_size)." height=".($image_size[1]*$this->img_preview_size);//開(kāi)源代碼Vevb.com 
  138.     $img_upload_sucess.=$img_src
  139.    } 
  140.       return $img_upload_sucess
  141.   } 
  142.  } 
  143.  
  144.  function __destruct() 
  145.  { 
  146.   //clear 
  147.  } 
  148.  } 

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 自治县| 永福县| 莲花县| 泰州市| 贵溪市| 东兰县| 高邮市| 锦屏县| 吴忠市| 福建省| 迁西县| 东乌珠穆沁旗| 邢台县| 凌源市| 东丽区| 哈巴河县| 精河县| 城步| 安徽省| 永泰县| 水城县| 婺源县| 墨竹工卡县| 德格县| 华蓥市| 安龙县| 西畴县| 彭水| 油尖旺区| 柞水县| 思茅市| 九龙坡区| 大同县| 柏乡县| 剑河县| 体育| 铅山县| 定安县| 南投县| 宽城| 乐东|