<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ~~~ <?php /* 1.獲取上次圖片的信息 2.驗證上傳圖片的格式 3.驗證上傳圖片的大小 4.創建上傳目錄(如果沒有) 5.上傳文件到指定目錄下*/ class ShangChuan{ private $shuchuyuju; //輸出問題原因 private $swt; //定義所有問題屬性 private $geshi; //獲取圖片擴展名 private $da=5242880; //定義圖片最大值 private $b=['jpg','png','gif','JPG','PNG','GIF']; //文件格式判斷 private $tmax; //獲取圖片大小 private $dir='uploads'; //給定目錄 private $sub_dir; //子目錄 private $lishitu; //臨時圖片 function __construct($file) //構造函數 { $this->swt=$file['error']; //等于0問題賦值 $this->geshi=$file['name']; //獲取名稱 $this->tmax=$file['size']; //獲取圖片大小值 $this->lishitu=$file['tmp_name']; //臨時圖片地址 } public function shuchu():?string { //輸出到外部 if(!$this->yanzheng()){ return $this->shuchuyuju; } return '上傳成功'; } private function yanzheng():?string //驗證所有上傳圖總問題,并執行上傳圖片 { if($this->suoyouwenti()==false){ $this->shuchuyuju='上傳文件有問題'; return false; }elseif($this->wjname()==false){ //驗證圖片格式有問題 $this->shuchuyuju='文件非圖片格式'; return false; }elseif($this->tmax()==false){ $this->shuchuyuju='圖片大于5M'; return false; }elseif($this->mulu()==true){ $this->yidong(); } return true; } //檢測上傳信息 private function suoyouwenti():bool { if($this->swt!=0) { return false; //有問題的時候返回false } return true; } //驗證文件名稱 private function wjname():bool { $geshi=pathinfo($this->geshi,PATHINFO_EXTENSION); if(!in_array($geshi,$this->b)) { return false; } return true; } //檢測上傳禁止過大 默認5M private function tmax():bool{ if($this->tmax>$this->da) { return false; } return true; } //判斷是否有目錄,如果沒有創建 private function mulu():bool{ //$dir='uploads'; //給定目錄 $this->sub_dir=$this->dir.DIRECTORY_SEPARATOR.date('Y-m-d'); //創建以時間命名的子目錄 DIRECTORY_SEPARATOR 判斷輸目錄付號因為win與linx不一樣,所以要用這個 if(!is_dir($this->dir)){ //如果沒有upleads這個目錄創建出來 mkdir($this->dir); mkdir($this->sub_dir); //創建目錄 }elseif(!is_dir($this->sub_dir)){ mkdir($this->sub_dir); //創建子目錄 } return true; } //移動圖片到目錄 (最后一步了) private function yidong():?string{ $img_name=date('Ymdllis').rand(100,9999).'.'.$this->geshi; //生成隨機名字的圖片防止重名的 return move_uploaded_file($this->lishitu,$this->sub_dir.DIRECTORY_SEPARATOR.$img_name); } } $file=$_FILES['tupian']; $tupian= new ShangChuan($file); //構造函數傳值 echo $tupian->shuchu(); //實例化結果 ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看