php常用文件上传类php
_file = &$_FILES[$name];$this->_parseUploadFile();} else {die('No file upload.');}}/*** set upload target path** @param string $path* @return boolean*/ function setTarget($path = 'upload/') {if(is_dir($path)) {$this->target = rtrim($path,'/').'/';return true;} else {return false;}}/*** get the type of the file**/ function _parseUploadFile() {$type = $this->_file['type'];if(isset($type) && $type != '') {switch ($type) {case 'image/gif':$this->_fileType = 'gif';break;case 'image/png':$this->_fileType = 'png';break;case 'image/jpeg':$this->_fileType = 'jpg';break;case 'image/pjpeg':$this->_fileType = 'jpg';break;default:$this->_fileType = 'unknow';break;}} else {$filename = $this->_file['name'];$filename = explode('.',$filename);$filename = strtoupper($filename[sizeof($filename) - 1]);switch ($filename) {case 'PNG':$this->_fileType = 'png';break;case 'JPEG':$this->_fileType = 'jpg';break;case 'JPG':$this->_fileType = 'jpg';break;case 'GIF':$this->_fileType = 'gif';break;default:$this->_fileType = 'unknow';break;}unset($filename);}unset($type);}/*** upload file** @return array*/ function load() {if($this->_fileType == 'unknow') {die('Can not upload this file,because the type is not allow.');}if(file_exists($this->_file['tmp_name']) && is_uploaded_file($this->_file['tmp_name'])) {$new_file_name = $this->target.time().'.'.$this->_fileType;move_uploaded_file($this->_file['tmp_name'],$new_file_name);return array('name'=>$new_file_name,'size'=>$this->_file['size'],'type'=>$this->_fileType);} else {return false;}}}?>
相关文章
- PHP将整个网站生成HTML纯静态网页的方法总结
- 关于jq显示隐藏的成效
- C语言头文件<string.h>函数详解
- Python lambda函数(匿名函数)、参数类型与递归全解析
- NumPy 多维数组中正确使用元组索引访问特定轴的对角线元素
- SOL币是否触底?多维数据揭秘Solana真实现状
- 如何查询代币的当前流通量与最终总供应量?欧易行情币种详情页信息查看方法
- XML卷之实战锦囊(2):动态查询
- javascript - 如何解决 header("WWW-Authenticate: Basic realm='你好'")弹框中中文乱码的问题?
- AoC - Day 仔细考虑(C# 和 Python)
