upload_file.php
资源名称:BBWPS.rar [点击查看]
上传用户:yttaitong
上传日期:2009-05-10
资源大小:128k
文件大小:3k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
PHP
- <?
- /*
- [BBWPS!] (C)2006-2010 小蜜蜂版权所有.
- This is NOT a freeware, use is subject to license terms
- 时间:2007年12月
- 描述:上传文件
- */
- class upload_file {
- var $upfile_type,$upfile_size,$upfile_name,$upfile;
- var $d_alt,$extention_list,$tmp,$arri;
- var $datetime,$date;
- var $filestr,$size,$ext,$check;
- var $flash_directory,$extention,$file_path,$base_directory;
- var $url;
- function upload_file() {
- $this->set_url("index.php");
- $this->set_extention();
- $this->set_size(1024);
- $this->set_date();
- $this->set_datetime();
- $this->set_base_directory("attachmentFile");
- }
- function set_file_type($upfile_type) {
- $this->upfile_type = $upfile_type;
- }
- function set_file_name($upfile_name) {
- $this->upfile_name = $upfile_name;
- }
- function set_upfile($upfile) {
- $this->upfile = $upfile;
- }
- function set_file_size($upfile_size) {
- $this->upfile_size = $upfile_size;
- }
- function set_url($url) {
- $this->url = $url;
- }
- function get_extention() {
- $this->extention = preg_replace('/.*.(.*[^.].*)*/iU','\1',$this->upfile_name);
- }
- function set_datetime() {
- $this->datetime = date("YmdHis");
- }
- function set_date() {
- $this->date = date("Y-m-d");
- }
- function set_extention() {
- $this->extention_list = "gif|jpg|jpeg|bmp|png";
- }
- function set_size($size) {
- $this->size = $size;
- }
- function set_base_directory($directory) {
- $this->base_directory = $directory;
- }
- function set_flash_directory() {
- $this->flash_directory = $this->base_directory."/".$this->date;
- }
- function showerror($errstr="未知错误!"){
- echo "<script language=javascript>alert('$errstr');location='javascript:history.go(-1);';</script>";
- exit();
- }
- function go_to($str,$url) {
- echo "<script language='javascript'>alert('$str');location='$url';</script>";
- exit();
- }
- function mk_base_dir() {
- if (! file_exists($this->base_directory)){
- @mkdir($this->base_directory,0777);
- }
- }
- function mk_dir() {
- if (! file_exists($this->flash_directory)){
- @mkdir($this->flash_directory,0777);
- }
- }
- function get_compare_extention() {
- $this->ext = explode("|",$this->extention_list);
- }
- function check_extention() {
- for($i=0;each($this->ext);$i++)
- {
- if($this->ext[$i] == strtolower($this->extention)){
- $this->check = true;
- break;
- }
- }
- if(!$this->check){
- $this->showerror("正确的扩展名必须为".$this->extention_list."其中的一种!");
- }
- }
- function check_size() {
- if($this->upfile_size > round($this->size*1024)){
- $this->showerror("上传附件不得超过".$this->size."KB");
- }
- }
- function set_file_path() {
- $this->file_path = $this->flash_directory."/".$this->datetime.".".$this->extention;
- }
- function get_file_path(){
- return $this->file_path;
- }
- function save() {
- $this->set_flash_directory();
- $this->get_extention();
- $this->get_compare_extention();
- $this->check_extention();
- $this->check_size();
- $this->mk_base_dir();
- $this->mk_dir();
- $this->set_file_path();
- if(copy($this->upfile,$this->file_path)){
- return true;
- }else {
- return false;
- }
- }
- }
- ?>