国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Kekurangan dan penambahbaikan kod muat naik fail PHP
wklc2020
wklc2020 2020-03-01 14:25:21
0
1
1160
<?php  /**   * 單文件上傳   */  // 單文件上傳  class UploadFile {
    /**     * 構(gòu)造函數(shù)     * @param [File] $file 文件對(duì)象     */    function __construct($file) {      $this->upload_status = '';      $this->upload_message = '';      $this->file = $file;      $this->mime_map = array(        '.jpeg' => array('image/jpeg', 'image/pjpeg'),        '.jpg' => array('image/jpeg', 'image/pjpeg'),        '.png' => array('image/png', 'image/x-png'),        '.gif' => array('image/gif')      );      $this->allow_ext_list = array('.jpeg', '.jpg', '.png', '.gif');      $this->upload_path = './upload/';
      $this->checkFileParam();      $this->checkFileError();      $this->checkFileType();      $this->uploadStart();    }
    /**     * 驗(yàn)證是否傳入了正確的文件對(duì)象     * 必須包含[name, type, size, error, tmp_name]     */    private function checkFileParam() {      if ($this->upload_status === 'error') return;
      $file = $this->file;      $right_name = gettype($file['name']) === 'string';      $right_type = gettype($file['type']) === 'string';      $right_tmp_name = gettype($file['tmp_name']) === 'string';      $right_error = gettype($file['error']) === 'integer';      $right_size = gettype($file['size']) === 'integer';      if (!$right_name || !$right_type || !$right_tmp_name || !$right_error || !$right_size) {        $this->upload_message = '傳入的文件對(duì)象參數(shù)不合法!';        $this->upload_status = 'error';      }    }
    // 檢查文件對(duì)象接收的錯(cuò)誤信息    private function checkFileError() {      if ($this->upload_status === 'error') return;
      $error = $this->file['error'];
      if ($error == 0) return;
      switch ($error) {        case 1:          $upload_message = '上傳的文件超過了php.ini 中 upload_max_filesize 選項(xiàng)限制的值!';          break;        case 2:          $upload_message = '上傳文件的大小超過了 HTML 表單中 MAX_FILE_SIZE 選項(xiàng)指定的值!';          break;        case 3:          $upload_message = '文件只有部分被上傳!';          break;        case 4:          $upload_message = '沒有文件被上傳!';          break;        case 6:          $upload_message = '找不到臨時(shí)文件夾!';          break;        case 7:          $upload_message = '文件寫入失?。?#39;;          break;        default:          $upload_message = '未知錯(cuò)誤!';          break;      }      $this->upload_status = 'error';      $this->upload_message = $upload_message;    }
    // 檢查上傳的文件 MIME 類型是否合法    private function checkFileType() {      if ($this->upload_status === 'error') return;
      $type = $this->file['type'];      $name = $this->file['name'];      $tmp_name = $this->file['tmp_name'];      $allow_ext_list = $this->allow_ext_list;      $mime_map = $this->mime_map;
      // 后綴檢查      $ext_name = strtolower(strrchr($name, '.'));      if (!in_array($ext_name, $allow_ext_list)) {        $this->upload_status = 'error';        $this->upload_message = '上傳的文件類型不合法!';        return;      }
      // 瀏覽器提供信息堅(jiān)持      $allow_mime_list = array();      foreach($allow_ext_list as $val) {        $allow_mime_list = array_merge($allow_mime_list, $mime_map[$val]);      }      $allow_mime_list = array_unique($allow_mime_list);      if (!in_array($type, $allow_mime_list)) {        $this->upload_status = 'error';        $this->upload_message = '上傳的文件類型不合法!';        return;      }
      // php自身檢查      // 需要開啟 extension=fileinfo      $file_mime = new Finfo(FILEINFO_MIME_TYPE);      $mime = $file_mime->file($tmp_name);      if (!in_array($mime, $allow_mime_list)) {        $this->upload_status = 'error';        $this->upload_message = '上傳的文件類型不合法!';        return;      }    }
    // 文件上傳    private function uploadStart() {      if ($this->upload_status === 'error') return;
      $name = $this->file['name'];      $tmp_name = $this->file['tmp_name'];      $ext_name = strtolower(strrchr($name, '.'));      $base_name = 'UPLOAD_' . md5(uniqid());      $upload_path = $this->upload_path;
      // 上傳路徑檢查      if (!is_dir($upload_path)) {        mkdir($upload_path);      }
      // is_uploaded_file($file) 檢查指定的文件是否是通過 HTTP POST 上傳的      // 如果文件是通過 HTTP POST 上傳的,該函數(shù)返回 TRUE。      if (is_uploaded_file($tmp_name)) {
        // move_uploaded_file($file, $path) 函數(shù)將上傳的文件移動(dòng)到新位置。        // 若成功,則返回 true,否則返回 false。        if (move_uploaded_file($tmp_name, $upload_path . $base_name . $ext_name)) {          $this->upload_status = 'success';          $this->upload_message = '文件上傳成功!';          return ;        } else {          // 需要寫入權(quán)限          $this->upload_message = '無法移動(dòng)文件到指定位置!';        }      } else {        $this->upload_message = '文件必須通過 HTTP POST 方式上傳!';      }      $this->upload_status = 'error';    }  }?>


wklc2020
wklc2020

membalas semua(1)
wklc2020

Format kacau, macam mana nak edit topik?

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan