PHP之圖片上傳類實例代碼(加了縮略圖)_PHP實例_積木網(gimoo.net) var artID=\'403087\',artSID=\'15\',artBBS=\'2\'; jQuery(function($){ $(\'pre\').each(function(i){ if ($(this).find(\'code\').length==0) $(this).ht">

成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? PHP之圖片上傳類實例代碼(加了縮略圖)
全站頭部文字 我要出現在這里
PHP之圖片上傳類實例代碼(加了縮略圖) 701 2024-01-31   

有縮略圖功能 但是 感覺不全面,而且有點問題,繼續學習,將來以后修改下

<form action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post" ><input type="text" name="name" /><input type="file" name="file" /><input type="submit" name='submit' value="提交" ></form> 
 
<?php 
/** 
 * Created by PhpStorm. 
 * User: Administrator 
 * Date: 2016/6/28 
 * Time: 21:04 
 */
 
class upload{ 
   protected $fileMine;//文件上傳類型 
   protected $filepath;//文件上傳路徑 
   protected $filemax;//文件上傳大小 
   protected $fileExt;//文件上傳格式 
   protected $filename;//文件名 
   protected $fileerror;//文件出錯設置 
   protected $fileflag;//文件檢測 
   protected $fileinfo; //FILES 
   protected $ext; //文件擴展 
   protected $path; 
 
  //文件上傳 
  public function __construct($filename="file",$filemax=20000000,$filepath="./Uploads",$fileflag=true,$fileExt=array('jpg','exe'),$fileMine=array('image/jpeg')) 
  { 
    $this->filename=$filename; 
    $this->fileinfo=$_FILES[$this->filename]; 
    $this->filemax=$filemax; 
    $this->filepath=$filepath; 
    $this->fileflag=$fileflag; 
    $this->fileExt=$fileExt; 
    $this->fileMine=$fileMine; 
 
    //var_dump($this->filename); 
 
  } 
 
  //錯誤判斷 
  public function UpError(){ 
 
      if($this->fileinfo['error']>0){ 
        switch($this->fileinfo['error']) 
        { 
          case 1: 
          $this->fileerror="上傳文件大小超過服務器允許上傳的最大值,php.ini中設置upload_max_filesize選項限制的值 "; 
            break; 
          case 2: 
            $this->fileerror="上傳文件大小超過HTML表單中隱藏域MAX_FILE_SIZE選項指定的值"; 
            break; 
          case 3: 
            $this->fileerror="文件部分被上傳"; 
            break; 
          case 4: 
            $this->fileerror="沒有選擇上傳文件"; 
            break; 
          case 5: 
            $this->fileerror="未找到臨時目錄"; 
            break; 
          case 6: 
            $this->fileerror="文件寫入失敗"; 
            break; 
          case 7: 
            $this->fileerror="php文件上傳擴展沒有打開 "; 
            break; 
          case 8: 
            $this->fileerror=""; 
            break; 
 
        } 
        return false; 
      } 
      return true; 
 
  } 
 
  //檢測文件類型 
  public function UpMine(){ 
    if(!in_array($this->fileinfo['type'],$this->fileMine)) { 
      $this->error="文件上傳類型不對"; 
      return false; 
    } 
    return true; 
 
  } 
  //檢測文件格式 
  public function UpExt(){ 
    $this->ext=pathinfo($this->fileinfo['name'],PATHINFO_EXTENSION); 
    //var_dump($ext); 
    if(!in_array($this->ext,$this->fileExt)){ 
      $this->fileerror="文件格式不對"; 
      return false; 
    } 
    return true; 
  } 
  //檢測文件路徑 
  public function UpPath(){ 
    if(!file_exists($this->filepath)){ 
      mkdir($this->filepath,0777,true); 
    } 
  } 
  //檢測文件大小 
  public function UpSize(){ 
    $max=$this->fileinfo['size']; 
    if($max>$this->filemax){ 
      $this->fileerror="文件過大"; 
      return false; 
    } 
    return true; 
  } 
  //檢測文件是否HTTP 
  public function UpPost(){ 
    if(!is_uploaded_file($this->fileinfo['tmp_name'])){ 
      $this->fileerror="惡意上償還"; 
      return false; 
    } 
    return true; 
  } 
  //文件名防止重復 
  public function Upname(){ 
    return md5(uniqid(microtime(true),true)); 
  } 
 
  //圖片縮略圖 
  public function Smallimg($x=100,$y=100){ 
    $imgAtt=getimagesize($this->path); 
    //圖像寬,高,類型 
    $imgWidth=$imgAtt[0]; 
    $imgHeight=$imgAtt[1]; 
    $imgext=$imgAtt[2]; 
    //等比列縮放 
 
    if(($x/$imgWidth)>($y/$imgHeight)){ 
      $bl=$y/$imgHeight; 
    }else{ 
      $bl=$x/$imgWidth; 
    } 
    $x=floor($imgWidth*$bl); //縮放后 
    $y=floor($imgHeight*$bl); 
    $images=imagecreatetruecolor($x,$y); 
    $big=imagecreatefromjpeg($this->path); 
    imagecopyresized($images,$big,0,0,0,0,$x,$y,$imgWidth,$imgWidth); 
    switch($imgext){ 
      case 1: 
        $imageout=imagecreatefromgif($this->path); 
        break; 
      case 2: 
        $imageout=imagecreatefromjpeg($this->path); 
        break; 
      case 3: 
        $imageout=imagecreatefromgif($this->path); 
        break; 
    } 
    $im=imagejpeg($images,$this->path); 
 
 
 
 
  } 
 
  //文件雙傳 
  public function uploads() 
  { 
    if($this->UpError()&&$this->UpMine()&&$this->UpExt()&&$this->UpSize()&&$this->UpPost()){ 
      $this->UpPath(); 
      $names=$this->Upname(); 
      $this->path=$this->filepath.'/'. $names.'.'.$this->ext; 
 
      if(move_uploaded_file($this->fileinfo['tmp_name'], $this->path)){ 
        return $this->path; 
      }else{ 
        $this->fileerror="上傳失敗"; 
      } 
    }else{ 
      exit("<b>".$this->fileerror."</b>"); 
    } 
  } 
 
 
} 
 
 
?>
<?php 
  header("content-type:imagejpeg"); 
header("Content-type:text/html;charset=utf-8"); 
 require 'list.php'; 
 $u=new upload(); 
 $a=$u->uploads(); 
 
 $c=$u->Smallimg(); 
echo "<img src={$a} />"; 
echo "<img src={$c} />"; 
 
?> 
<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<title>Examples</title> 
<meta name="description" content=""> 
<meta name="keywords" content=""> 
<link  rel="stylesheet"> 
</head> 
<body> 
  <form action="ce.php" enctype="multipart/form-data" method="post" > 
  <input type="text" name="name" /><input type="file" name="file" /> 
  <input type="submit" name='submit' value="提交" > 
  </form> 
</body> 
</html>

以上這篇PHP之圖片上傳類實例代碼(加了縮略圖)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持綠夏網。



主站蜘蛛池模板: 古宅老友记第四季| 我的m属性学姐| 女同性激烈床戏舌吻戏| 香港九龙图库精选资料| 吻戏韩国电影| 女人战争之肮脏的交易 剧情简介| 日韩成人av电影77777| 正在行动| 阿尔法变频器说明书| 色女孩视频| 单人头像| 江雪谢君尧短剧| 17岁韩国电影完整版观看免费| 喜羊羊电影| 艳女十八式无删除版| 冒险王2| 别姬| 对你的爱歌词| 一闪一闪亮晶晶电影免费| 刘永健| 斑点狗动画片| 心理健康《微笑的力量》ppt| 挠vk| 玛丽与魔女之花| 豆花电影免费播放| 林栋浦| 微信图像男| 色天使美国| 日本大片ppt免费ppt视频| 玛丽·杜布瓦| 哈尔的移动城堡电影| 海洋之歌免费观看完整中文版 | 正在恋爱中 电视剧韩剧免费全集结局| 程嘉美电影| 贵州三日游| 朱一龙电视剧| 重温经典频道在线直播| 李洋简介| 漫画启示作文五年级| 快手快枪快手演员表| 野蛮人电影|

!!!站長長期在線接!!!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103