亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PHP之圖片上傳類實例代碼(加了縮略圖)

 更新時間:2016年06月30日 09:58:53   投稿:jingxian  
下面小編就為大家?guī)硪黄狿HP之圖片上傳類實例代碼(加了縮略圖)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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

<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 href="" 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之圖片上傳類實例代碼(加了縮略圖)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • PHP中的流(streams)淺析

    PHP中的流(streams)淺析

    這篇文章主要介紹了PHP中的流(streams)淺析,本文講解了流的概述 、流基礎知識、php://包裝器、流上下文(Stream Contexts)等內(nèi)容,需要的朋友可以參考下
    2015-07-07
  • Laravel框架實現(xiàn)利用監(jiān)聽器進行sql語句記錄功能

    Laravel框架實現(xiàn)利用監(jiān)聽器進行sql語句記錄功能

    這篇文章主要介紹了Laravel框架實現(xiàn)利用監(jiān)聽器進行sql語句記錄功能,結合實例形式分析了Laravel框架監(jiān)聽器的創(chuàng)建、引入以及使用監(jiān)聽器記錄sql語句的相關操作技巧,需要的朋友可以參考下
    2018-06-06
  • PHP面向對象編程之深入理解方法重載與方法覆蓋(多態(tài))

    PHP面向對象編程之深入理解方法重載與方法覆蓋(多態(tài))

    這篇文章主要介紹了PHP面向對象編程之深入理解方法重載與方法覆蓋(多態(tài))的相關資料,需要的朋友可以參考下
    2015-12-12
  • 可以在線執(zhí)行PHP代碼包裝修正版

    可以在線執(zhí)行PHP代碼包裝修正版

    在寒竹、Fanbin等等熱心的朋友的幫助下,這款小巧的程序終于誕生了。 想做這款程序的初衷是方便測試一些代碼,這樣就不用新建文件->輸入代碼->保存->打開瀏覽器->定位到php文件->查看瀏覽結果這么一個繁瑣的過程了,現(xiàn)在只要把地址保存到收藏夾,然后要測試的時候,拿出來,直接輸入代碼測試就行了。 代碼輸入也挺方便的,自動高亮、自動完成,當然不支持代碼提示
    2008-03-03
  • PHP與Ajax相結合實現(xiàn)登錄驗證小Demo

    PHP與Ajax相結合實現(xiàn)登錄驗證小Demo

    AJAX即“Asynchronous Javascript And XML”(異步JavaScript和XML),是指一種創(chuàng)建交互式網(wǎng)頁應用的網(wǎng)頁開發(fā)技術。接下來通過本文給大家分享PHP與Ajax相結合實現(xiàn)登錄驗證小Demo,對php ajax實現(xiàn)登錄驗證相關知識感興趣的朋友一起學習吧
    2016-03-03
  • YII2框架中使用yii.js實現(xiàn)的post請求

    YII2框架中使用yii.js實現(xiàn)的post請求

    本文給大家介紹的是簡單分析下用yii2的yii\helpers\Html類和yii.js實現(xiàn)的post請求的方法,非常的簡單,有需要的小伙伴可以參考下
    2017-04-04
  • php獲取、檢查類名、函數(shù)名、方法名的函數(shù)方法

    php獲取、檢查類名、函數(shù)名、方法名的函數(shù)方法

    這篇文章主要介紹了php獲取、檢查類名、函數(shù)名、方法名的函數(shù)方法,本文匯總介紹7個函數(shù)的作用和使用介紹,需要的朋友可以參考下
    2015-06-06
  • PHP判斷字符串長度的兩種方法很實用

    PHP判斷字符串長度的兩種方法很實用

    這篇文章主要介紹了PHP判斷字符串長度的相關資料,需要的朋友可以參考下
    2015-09-09
  • 在PHP中使用X-SendFile頭讓文件下載更快

    在PHP中使用X-SendFile頭讓文件下載更快

    這篇文章主要介紹了在PHP中讓文件下載更快的一個方法,那就是使用X-SendFile頭實現(xiàn),主流量的服務器都支持這個頭文件,的朋友可以參考下
    2014-06-06
  • php支付寶APP支付功能

    php支付寶APP支付功能

    這篇文章主要為大家詳細介紹了php支付寶APP支付功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-07-07

最新評論