第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

老師你好,我根據(jù)你講解的代碼編寫后,封裝上傳文件對象后,上傳文件總是報文件擴展類型錯誤,調(diào)試后fileInfo信息位NULL

<?php
/**
* Created by PhpStorm.
* User: andin
* Date: 16-3-18
* Time: 上午9:29
*/
class upload{
? ?protected $fileName;
? ?protected $maxSize;
? ?protected $allowMime;
? ?protected $allowExt;
? ?protected $uploadPath;
? ?protected $imgFlag;
? ?protected $fileInfo;
? ?protected $error;
? ?protected $ext;

? ?/**
? ? * @param string $fileName
? ? * @param string $uploadPath
? ? * @param int $maxSize
? ? * @param bool $imgFlag
? ? * @param array $allowMime
? ? * @param array $allowExt
? ? */
? ?public function _construct($fileName='myfile',$uploadPath='./upload',$maxSize=5242880,$imgFlag=true,$allowMime=array('image/jpeg','image/png','image/gif','image/jpg'),$allowExt=array('jpg','jpeg','txt','png','gif','bmp')){
? ? ? ?$this->fileName=$fileName;
? ? ? ?$this->maxSize=$maxSize;
? ? ? ?$this->allowMime=$allowMime;
? ? ? ?$this->allowExt=$allowExt;
? ? ? ?$this->uploadPath=$uploadPath;
? ? ? ?$this->imgFlag=$imgFlag;
? ? ? ?$this->fileInfo=$_FILES[$this->fileName];
? ?}

? ?/**
? ? * 檢測是否出錯
? ? * @return bool
? ? */
? ?protected function checkError(){

? ? ? ?//if(!is_null($this->fileInfo)) {



? ? ? ? ? ?if ($this->fileInfo['error'] > 0) {
? ? ? ? ? ? ? ?switch ($this->fileInfo['error']) {
? ? ? ? ? ? ? ? ? ?case 1:
? ? ? ? ? ? ? ? ? ? ? ?$this->error = '超過了php配置文件中upload選項的值';
? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ?case 2:
? ? ? ? ? ? ? ? ? ? ? ?$this->error = '超過了表單中的限制';
? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ?case 3:
? ? ? ? ? ? ? ? ? ? ? ?$this->error = '文件上傳不完整';
? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ?case 4:
? ? ? ? ? ? ? ? ? ? ? ?$this->error = '沒有選擇上傳目錄';
? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ?case 6:
? ? ? ? ? ? ? ? ? ? ? ?$this->error = '沒有找到臨時目錄';
? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ?case 7:
? ? ? ? ? ? ? ? ? ? ? ?$this->error = '文件不可寫';
? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ?case 8:
? ? ? ? ? ? ? ? ? ? ? ?$this->error = '由于php擴展程序中斷上傳';
? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?return false;
? ? ? ? ? ?}else {
? ? ? ? ? ? ? ?//echo 'aa';
? ? ? ? ? ? ? ?return true;
? ? ? ? ? ?}
? ? ? ?//} else{
? ? ? ?// ? ? ? ?$this->error='文件上傳錯誤';
? ? ? ?// ? ? ? ?return false;
? ? ? ? // ? }

? ?}


? ?/**
? ? * 檢測上傳文件大小
? ? * @return bool
? ? */
? ?protected function checkSize(){
? ? ? ?if($this->fileInfo['size']>$this->maxSize){
? ? ? ? ? ?$this->error='上傳文件過大';
? ? ? ? ? ?return false;
? ? ? ?}
? ? ? ?return true;
? ?}

? ?/**
? ? *檢測擴展名
? ? * @return bool
? ? */
? ?protected function checkExt(){
? ? ? // $this->ext=strtolower(pathinfo($this->fileInfo['name'],PATHINFO_EXTENSION));
? ? ? ?$this->ext=strtolower(pathinfo($this->fileInfo['name'],PATHINFO_EXTENSION));
? ? ? ?echo 'bb';
? ? ? ?//var_dump($this->fileInfo['name']);
? ? ? ?var_dump($this->ext);
? ? ? ?if(!in_array($this->ext,$this->allowExt)){
? ? ? ? ? ?$this->error='不允許的擴展名';
? ? ? ? ? ?return false;
? ? ? ?}
? ? ? ?return true;
? ?}

? ?/**
? ? * 檢測文件類型
? ? * @return bool
? ? */

? ?protected function checkMime(){
? ? ? ?if(!in_array($this->fileInfo['type'],$this->allowMime)){
? ? ? ? ? ?$this->error='不允許的文件類型';
? ? ? ? ? ?return false;
? ? ? ?}
? ? ? ?return true;
? ?}

? ?/**
? ? * 檢測圖片是否真實
? ? * @return bool
? ? */
? ?protected function checkTrueImg(){
? ? ? ?if($this->imgFlag){
? ? ? ? ? ?if(!@getimagesize($this->fileInfo['tmp_name'])){
? ? ? ? ? ? ? ?$this->error='不是真實的圖片';
? ? ? ? ? ? ? ?return false;
? ? ? ? ? ?}
? ? ? ? ? ?return true;
? ? ? ?}
? ?}

? ?/**
? ? * 檢測文件是否通過http post方式上傳
? ? * @return bool
? ? */
? ?protected function checkHTTPPost(){
? ? ? ?if(!is_uploaded_file($this->fileInfo['tmp_name'])){
? ? ? ? ? ?$this->error='文件不是通過http post方式上傳的';
? ? ? ? ? ?return false;
? ? ? ?}
? ? ? ?return true;
? ?}

? ?/**
? ? * 獲取錯誤信息
? ? */
? ?protected function showError(){
? ? ? ?exit('<span style="color: red">'.$this->error.'</span>');
? ?}

? ?/**
? ? * 檢測目錄不存在就創(chuàng)建
? ? */
? ?protected function checkUploadPath(){
? ? ? ?if(!file_exists($this->uploadPath)){
? ? ? ? ? ?mkdir($this->uploadPath,0777,true);
? ? ? ?}
? ?}

? ?/**
? ? * 產(chǎn)生唯一字符竄當文件名
? ? * @return string
? ? */
? ?protected function getUniName(){
? ? ? ?return md5(uniqid(microtime(true),true));
? ?}

? ?/**
? ? * 上傳文件
? ? * @return string
? ? */

? ?public function loadFile(){
? ? ? ?var_dump($this->fileInfo['name']);
? ? ? ?if($this->checkError()&&$this->checkSize()&&$this->checkExt()&&$this->checkMime()&&$this->checkTrueImg()&&$this->checkHTTPPost()){
? ? ? ? ? ?$this->checkUploadPath();
? ? ? ? ? ?$this->uniName=$this->getUniName();
? ? ? ? ? ?$this->destination=$this->uploadPath.'/'.$this->uniName.'.'.$this->ext;
? ? ? ? ? ?if(@move_uploaded_file($this->fileInfo['tmp_name'],$this->destination)){
? ? ? ? ? ? ? ?return $this->destination;

? ? ? ? ? ?}else{
? ? ? ? ? ? ? ?$this->error='文件移動失敗';
? ? ? ? ? ? ? ?$this->showError();
? ? ? ? ? ?}







? ? ? ?}else{
? ? ? ? ? ?$this->showError();
? ? ? ?}
? ?}






}http://img1.sycdn.imooc.com//56ebb54900011b3614400900.jpg

正在回答

1 回答

你視頻沒有看完吧?

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
PHP實現(xiàn)文件上傳與下載
  • 參與學習       43749    人
  • 解答問題       335    個

本課程講解了文件上傳的原理和配置,學會兩種方式實現(xiàn)文件上傳與下載

進入課程

老師你好,我根據(jù)你講解的代碼編寫后,封裝上傳文件對象后,上傳文件總是報文件擴展類型錯誤,調(diào)試后fileInfo信息位NULL

我要回答 關注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號