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

首頁 > 編程 > PHP > 正文

適用于初學者的簡易PHP文件上傳類

2020-03-22 18:18:14
字體:
來源:轉載
供稿:網(wǎng)友
if (!is_dir($path) || !is_writable($path)){ throw new Exception("文件名不可寫,或者不是目錄!"); $this- _destination = $path; $this- _uploaded = $_FILES; * 移動文件 html' target='_blank'>public function move(){ $filed = current($this- _uploaded); $isOk = $this- checkError($filed['name'], $filed['error']); //debug ok if ($isOk){ $sizeOk = $this- checkSize($filed['name'], $filed['size']); $typeOk = $this- checkType($filed['name'], $filed['type']); if ($sizeOk && $typeOk){ $success = move_uploaded_file($filed['tmp_name'], $this- _destination.$filed['name']); if ($success){ $this- _messages[] = $filed['name']."文件上傳成功"; }else { $this- _messages[] = $filed['name']."文件上傳失敗"; * 查詢messages數(shù)組內(nèi)容 public function getMessages(){ return $this- _messages; * 檢測上傳的文件大小 * @param mix $string * @param int $size public function checkSize($filename, $size){ if ($size == 0){ return false; }else if ($size $this- _max){ $this- _messages[] = "文件超出上傳限制大小".$this- getMaxsize(); return false; }else { return true; * 檢測上傳文件的類型 * @param mix $filename * @param mix $type protected function checkType($filename, $type){ if (!in_array($type, $this- _permited)){ $this- _messages[] = "該文件類型是不被允許的上傳類型"; return false; }else { return true; * 獲取文件大小 public function getMaxsize(){ return number_format($this- _max / 1024, 1).'KB'; * 檢測上傳錯誤 * @param mix $filename * @param int $error public function checkError($filename, $error){ switch ($error){ case 0 : return true; case 1 : case 2 : $this- _messages[] = "文件過大!"; return true; case 3 : $this- _messages[] = "錯誤上傳文件!";return false; case 4 : $this- _messages[] = "沒有選擇文件!"; return false; default : $this- _messages[] = "系統(tǒng)錯誤!"; return false;希望本文所述對大家的php程序設計有所幫助。PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 沈阳市| 金寨县| 邵阳县| 郁南县| 马公市| 荆州市| 澎湖县| 北票市| 凤冈县| 濮阳市| 马关县| 吴旗县| 修文县| 儋州市| 曲阜市| 巴林右旗| 芜湖县| 五莲县| 玉屏| 大悟县| 绥德县| 曲沃县| 梁平县| 凤山市| 固原市| 介休市| 大理市| 丹东市| 红桥区| 浠水县| 大新县| 霍邱县| 寻甸| 毕节市| 石狮市| 曲松县| 峨山| 和政县| 望江县| 灵璧县| 郎溪县|