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

首頁 > 語言 > PHP > 正文

php實現(xiàn)常用文件上傳類的示例

2024-05-05 00:00:01
字體:
來源:轉載
供稿:網友

廢話不多說,直接上代碼:

<?php/** * 上傳文件類 * @param _path : 服務器文件存放路徑 * @param _allowType : 允許上傳的文件類型和所對應的MIME * @param _file : 上傳的文件信息 */class Upload{ private $_path; private $_allowType; private $_file; /**  * 構造函數(shù)  * @param string : 服務器上存放上傳文件的路徑  */ function __construct( $path = '' ) {  $this->_path = $path;  $this->_allowType = array(    // images    'bmp' => 'image/x-ms-bmp',    'jpg' => 'image/jpeg',    'jpeg' => 'image/jpeg',    'gif' => 'image/gif',    'png' => 'image/png',    'tif' => 'image/tiff',    'tiff' => 'image/tiff',    'tga' => 'image/x-targa',    'psd' => 'image/vnd.adobe.photoshop',    //文本    'txt' => 'text/plain',    'php' => 'text/x-php',    'html' => 'text/html',    'htm' => 'text/html',    'js' => 'text/javascript',    'css' => 'text/css',    'rtf' => 'text/rtf',    'rtfd' => 'text/rtfd',    'py' => 'text/x-python',    'java' => 'text/x-java-source',    'rb' => 'text/x-ruby',    'sh' => 'text/x-shellscript',    'pl' => 'text/x-perl',    'sql' => 'text/x-sql',    //應用    'exe' => 'application/octet-stream',    'doc' => 'application/vnd.ms-word',    'docx' => 'application/vnd.ms-word',    'xls' => 'application/vnd.ms-excel',    'ppt' => 'application/vnd.ms-powerpoint',    'pps' => 'application/vnd.ms-powerpoint',    'pdf' => 'application/pdf',    'xml' => 'application/xml',    //音頻    'mp3' => 'audio/mpeg',    'mid' => 'audio/midi',    'ogg' => 'audio/ogg',    'mp4a' => 'audio/mp4',    'wav' => 'audio/wav',    'wma' => 'audio/x-ms-wma',    //視頻    'avi' => 'video/x-msvideo',    'dv' => 'video/x-dv',    'mp4' => 'video/mp4',    'mpeg' => 'video/mpeg',    'mpg' => 'video/mpeg',    'mov' => 'video/quicktime',    'wm' => 'video/x-ms-wmv',    'flv' => 'video/x-flv',    'mkv' => 'video/x-matroska'   ); } /**  * 上傳函數(shù)  * @param string : 表單元素的name 值  * @return [type]  */ public function upload( $txtName = '' ) {  $this->_file = $_FILES[$txtName];  if( $this->_file['error'] == 0){   $fileType = end( explode('.', $this->_file['name'] ));   $allowType = array();   foreach( $this->_allowType as $item=>$value ){    $allowType[] = $item;   }   if( !in_array($fileType, $allowType)){    die('上傳的文件格式不正確!');   }else{    if(move_uploaded_file($this->file['tmp_name'], ($this->path).$this->file['name']))     {      echo "<script>alert('上傳成功!')</script>";     }    else     {      echo "<script>alert('上傳失敗!');</script>";     }   }  }else{   //沒有正確上傳   switch ($this->file['error']){    case 1:     die('文件大小超過系統(tǒng)限制。');     break;    case 2:     die('文件大小超過預定義限制。');     break;    case 3:     die('文件為完全上傳。');     break;    case 4:     die('未上傳任何文件。');     break;    default:     die('上傳出錯');     break;   }  } } //end upload}

以上這篇php實現(xiàn)常用文件上傳類的示例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 乾安县| 洪湖市| 盖州市| 酒泉市| 叙永县| 西藏| 洛宁县| 青岛市| 新乡县| 徐水县| 南和县| 新蔡县| 襄垣县| 合江县| 丽江市| 上高县| 南川市| 视频| 内丘县| 辽宁省| 炎陵县| 松滋市| 鞍山市| 民和| 柳州市| 来凤县| 汝州市| 长海县| 合江县| 长海县| 宣威市| 全椒县| 井陉县| 汾阳市| 香格里拉县| 钦州市| 梁山县| 锦屏县| 腾冲县| 北海市| 江都市|