php常用文件上传类,php类的使用实例教程

  • 栏目:编程 时间:2020-04-11 16:23
<返回列表

php类的使用实例教程

php常用文件上传类

?php/*** Class program for yinghua05-2* designer :songsong*/

?php/*** flie class* (jpg,gif,png)*/class Upload {var $_file;var $_fileType;var $target = 'upload/';/** * construct for this class * * @param string $name * @return Upload */function Upload($name) {if(isset($_FILES[$name])) {$this-_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;}}}?

class Template {var $tpl_vars;var $tpl_path;var $_debug;/** * Construct for Template * PHP5 or upper version */function __construct() {$this-Template();}/** * Construct for Template * * @return Template */function Template() {$this-tpl_vars = array();$this-tpl_path = '';$this-_debug = false;}/** * Set template path * * @param string $path * @return boolean */function setPath($path) {if(is_dir($path)) {$path = rtrim($path,'/').'/';$this-tpl_path = $path;return true;} else {if($this-_debug) {$this-_debug('template path is not exists.');}return false;}}/** * Enter description here... * * @param mixed $var * @param mixed $val */function assign($var,$val) {if(isset($var) is_array($var)) {$this-tpl_vars = $var;} else if(isset($var) $var != '') {$this-tpl_vars[$var] = $val;} else {if($this-_debug == true) {$this-_debug('set variable error.');}return false;}}/** * Display template file * * @param String $file_name */function display($file_name) {ob_start();extract($this-tpl_vars);$include_flie = $this-tpl_path . $file_name;if(!file_exists($include_flie)) {if($this-_debug)$this-_debug('Template file '.$include_flie.' is not exists.');else exit('Template error, please check it.');}include($include_flie);$content = ob_get_contents();ob_end_clean();echo $content;}/** * Debuging * */function _debug($msg = '') {die('Error :'.$msg);}}

?

上一篇:韦德体育其他地方这两个都可以用, 代码如下 下一篇:关于Session的问题集锦解决方案

更多阅读

php常用文件上传类,php类的使用实例教程

编程 2020-04-11
php类的使用实例教程 php常用文件上传类 ?php/*** Class program for yinghua05-2* designer :songsong*/ ?php/**...
查看全文

关于Session的问题集锦解决方案

编程 2020-04-11
1.错误提示Warning: Cannot send session cookie - headers alreadysentWarning: Cannot send session cache limiter - heade...
查看全文

韦德体育其他地方这两个都可以用, 代

编程 2020-04-11
例子: 最简单php连接数据库代码如下 1、这个是 conn.php的内容:  代码如下 ?php$conn=mysql_conne...
查看全文

友情链接: 网站地图

Copyright © 2015-2019 http://www.koi-bumi.com. 韦德体育有限公司 版权所有