<?php
/**
 * [UQcms System] Copyright uqcms.com
 * QQ: 2200631718
 * Author: gj.name
 * This is NOT a freeware
*/
defined('IN_UQ') or exit('Access Denied'); class upload { static public function store($save_path, $new_name = null, $file_move = null){ if(empty($file_move)){ $data = array(); $fvalue = array_values($_FILES); $file_name = $fvalue[0]['name']; $file_type = $fvalue[0]['type']; $file_size = $fvalue[0]['size']; $file_tmp_name = $fvalue[0]['tmp_name']; }else{ $file_name = $file_move; $file_type = mime_content_type($file_move); $file_size = filesize($file_move); $file_tmp_name = $file_move; } if($file_name){ if(in_array($file_type,array('image/jpeg','image/gif', 'image/png'))){ if($file_size < ((1024*1024)*2)){ if(empty($new_name)){ $new_name = $save_path.'/'.self::reset_file_name($file_name); } self::make_dir($new_name); if(move_uploaded_file($file_tmp_name, $new_name)){ $data['error'] = '0'; $data['name'] = $new_name; $data['url'] = $new_name; $data['size'] = filesize($new_name); }else{ $data['error'] = '1'; $data['msg'] = '上传错误'; } }else{ $data['error'] = '1'; $data['msg'] = '上传文件过大,当前图片'.formatBytes($file_size); } }else{ $data['error'] = '1'; $data['msg'] = '不支持此类型的文件,支持：jpg,gif,png'; } }else{ $data['error'] = '1'; $data['msg'] = '上传的文件不能为空'; } return $data; } static public function reset_file_name($file_name){ $pic_data = date("y").'/'.date("md").'/'.(date("his",time()).microtime()*1000000).'.'.self::getExt($file_name); return $pic_data; } static public function make_dir($file, $up_dir = ''){ $dir_path_file = explode('/',$file); array_pop($dir_path_file); $rootdir = array_shift($dir_path_file); if(($rootdir != '.'|| $rootdir != '..')&&!file_exists($rootdir)){ @mkdir($rootdir); } $dirlist = ''; foreach($dir_path_file as $key=>$val){ if($val != '.' && $val != '..'){ $dirlist .= "/".$val; $dirpath = $rootdir.$dirlist; if(!file_exists($dirpath)){ @mkdir($dirpath); @chmod($dirpath,0777); } } } } static public function getExt($path){ $path = pathinfo($path); return strtolower($path['extension']); } static public function mk_dirs($path,$up_dir = ''){ $adir = explode('/',$path); $dirlist = $up_dir; $rootdir = array_shift($adir); if(($rootdir != '.'|| $rootdir != '..')&&!file_exists($rootdir)){ @mkdir($rootdir); } foreach($adir as $key=>$val){ if($val != '.' && $val != '..'){ $dirlist .= "/".$val; $dirpath = $rootdir.$dirlist; if(!file_exists($dirpath)){ @mkdir($dirpath); @chmod($dirpath,0777); } } } } } 