⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upload.class.php

📁 网络硬盘_支持1GB文件上传和续传_无错版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/*+--------------------------------------------------------------------------|   Mega File Hosting Script v1.2|   ========================================|   by Stephen Yabziz|   (c) 2005-2006 YABSoft Services|   http://www.yabsoft.com|   ========================================|   Web: http://www.yabsoft.com|   Email: ywyhnchina@163.com+--------------------------------------------------------------------------||   > Script written by Stephen Yabziz|   > Date started: 1th March 2006+--------------------------------------------------------------------------*//*** @package MFHS* Uploader class*/class uploader {	/** basic infomation */    var $upload_session = null;    var $access_code    = '';    var $upload_mode    = 1;    var $upload_method  = array('can_formupload','can_ftpupload','can_urlupload','can_flashupload');    var $server_id      = 0;    var $upload_dir     = 'files';    var $temp_dir       = 'temp';    var $upload_time    = 0;    var $uploaded_num   = 0;    var $uploaded_size  = 0;    var $upload_start   = 0;    var $uploaded_files = array();    var $uploader_id    = 0;        var $timeout        = 0;    var $max_uploads    = 10;        var $upload_errors  = null;        /**upload url*/    var $upload_url='';    var $applet_upload_url='';        var $extras      = array();    var $sizelimit   = 1000000000000;    var $typelimit   = array();    var $typelimit2  = array();        var $size_func   = array(2=>'getUrlFileSize',3=>'getFTPFileSize');    var $get_func    = array(1=>'getLocalFile',2=>'getUrlFile',3=>'getFTPFile',4=>'getLocalFile');        var $progbar     = 'total';//or 'single'    var $progtype    = 'ajax';//or 'syn'	/**	* uploader object constructor	*/	function uploader($server_id=1,$type=0)    {    global $db, $DATASTORE;        $this->server_id     = $server_id;                # new added        $this->upload_server = $DATASTORE[servers][$server_id];        # used in ver 1.1        if($type==1&&!$this->upload_server)        {            $db->setQuery("select * from server where server_id='$server_id'");            $db->query();            $server = $db->loadRow();            # for flash upload use!            $this->server_domain = $server[domain];                        #            $this->upload_server = $server;        }                #        $this->upload_dir = $this->upload_server[upload_dir];        $this->keep_ext   = $this->upload_server[keepext]=='yes';	}    function setUploadMode($upload_mode)    {        $this->upload_mode = $upload_mode;        if($upload_mode == 1) $this->progtype    = $this->upload_server[cgi_prog_mode];        if($upload_mode == 2) $this->progtype    = $this->upload_server[url_prog_mode];        if($upload_mode == 3) $this->progtype    = $this->upload_server[ftp_prog_mode];        if($upload_mode == 1)        {            $this->temp_dir = $this->upload_server[cgi_temp_dir];        }        else        {            $this->temp_dir = $this->upload_server[php_temp_dir];        }    }    function create_session($user_id=0)    {        $session = md5(microtime());        $this->access_code    = base64_encode(encryptStr("$user_id",$session));        $this->upload_session = $session;	}    function validate_session(&$user,$access_code,$upload_session)    {        $this->access_code    = $access_code;        $this->upload_session = preg_replace('/[^a-z0-9]/','',$upload_session);        $uid = decryptStr(base64_decode($this->access_code),$this->upload_session);        if(is_numeric($uid))        {            $this->uploader_id = $uid;            # assign var from script vitually!            $_SESSION['uid']=$uid;            $_SESSION['logined']=1;            $_SESSION['last_click']=time();            $user = new user('session');            $user->initiate();                        $this->sizelimit   = $user->allowed_filesize;            $this->typelimit   = $user->allowed_filetypes;            $this->typelimit2  = $user->disabled_filetypes;            $this->max_uploads = $user->max_uploads;                        return true;        }        $this->setError('invalid upload session!');        return false;	}    function accept($files)    {    global $db,$user,$input;        # empty the vars        $this->uploaded_files = array();        $this->uploaded_num   = 0;        $this->upload_time    = time();                # slice the files and keep the key unchanged        $s = 0;$sliced_files=array();        foreach($files as $k=>$v)        {            $s++;            if($s>$this->max_uploads) break;            $sliced_files[$k]=$v;;        }        $files = $sliced_files;                if(count($files)==0) $this->setError('No upload files found!');                # get total size for url upload and ftp upload        if($this->upload_mode!=1&&$this->upload_mode!=4)        {            if($this->progbar=='total')            {                $this->upload_start = time();                $files = $this->getTotalSize($files);            }            # syn progress            if($this->progtype=='syn')            {                flush();                # avoid cache in IE browser!                echo str_repeat(' ',256);            }            # ajax progress            if($this->progtype=='ajax'&&$this->progbar=='total')            {                $monitor_file = $this->upload_session.'_flength';                $fp2=fopen($this->temp_dir.'/'.$monitor_file,'wb');                fwrite($fp2,$this->total_size);                fclose($fp2);            }        }        flush();        # process every file        foreach($files as $id=>$tmpfile)        {            # get html id to identify the description and password for form upload            if($this->upload_mode==4) $id = 0;            # assign start time            if($this->progbar=='single') $this->upload_start = time();            # get file            $function = $this->get_func[$this->upload_mode];            $file     = $this->$function($tmpfile);            if($file[error]) {$this->setError($file[errinfo]);continue;}            # move the temporay file to upload_dir            if(!copy($file[tmp_name], $this->upload_dir.'/'.$file[filename]))            {                $this->setError('copy error:Max Upload Size or Upload directory can not be writen in');                continue;            }                        # get extras information            $this->temps=$extras   = array('descr'=>$this->extras['descr'][$id],'password'=>$this->extras['password'][$id]);            # record into db            $fileobj  = $this->insertDB($file,$extras);            # check insert...            $insertid = $fileobj->id;            if($insertid==0) break;            #delete the temporay files            @unlink($file[tmp_name]);            #uploaded...            $this->uploaded_files[$insertid] = $fileobj;            $this->uploaded_num++;            $this->uploaded_size=$this->uploaded_size+$file[size];        }                # ajax progress        if($this->upload_mode!=1 && $this->progtype=='ajax' && $this->progbar=='total')        {            $signal_file  = $this->upload_session.'_signal';            $fp2=fopen($this->temp_dir.'/'.$signal_file,'wb');            fclose($fp2);        }        # upload is finished,do some updates on user's stats and redirect...        $this->uploadStats();    }    function getTotalSize($files)    {        $returns = array();        $this->total_size = 0;        # process every file        foreach($files as $key=>$tmpfile)        {            if(strlen($tmpfile)==0) continue;            # get file size            $function = $this->size_func[$this->upload_mode];            $file     = $this->$function($tmpfile);            if($file[error]) {$this->setError($file[errinfo]);continue;}                        $returns[$key] = $tmpfile;            $this->total_size=$this->total_size+$file[size];        }        return $returns;    }    function uploadStats()    {    global $db;         # update the users stats         if($this->uploader_id!=0&&$this->uploaded_num)         {             $db->setQuery("update users set files=files+$this->uploaded_num where id='$this->uploader_id'");             $db->query();         }         # update the server stats         if($this->uploaded_num)         {             $db->setQuery("update server set hosted=hosted+$this->uploaded_num,webspace=webspace+$this->uploaded_size where server_id='$this->server_id'");             $db->query();         }    }    function getUploadIDs()    {    global $db;        $db->setQuery("select id,name,size,descr,password,delete_id,upload_id from files where upload_session='$this->upload_session'");        $db->query();        return $db->loadRowList();    }    function checkFile(&$file)    {        $filesize = $file[size];        $filetype = getExt($file[name]);        if($filesize>$this->sizelimit           ||($this->typelimit&&!in_array($filetype,$this->typelimit))           ||($this->typelimit2&&in_array($filetype,$this->typelimit2)))        {            $file[error] = 1;            $file['errinfo']="Size $filesize ($this->sizelimit)  or type $filetype error";        }        else        {            $file[error] = 0;        }                return !$file[error];    }    function getUrlFile($uri)    {        $filename=basename($uri);        $filetype=getExt($filename);                # system used file        $data_file     = $this->upload_session.'_postdata';        $progress_file = $this->upload_session.'_progress';        $monitor_file  = $this->upload_session.'_flength';        $signal_file   = $this->upload_session.'_signal';                # construct the tmpfile        $tmpfile=array('name'=>$filename);        $http = new http_class();                $http->timeout = $this->timeout;        $http->data_timeout = $this->timeout;        $error=$http->GetRequestArguments($uri,$arguments);        $arguments["Headers"]["Pragma"]="nocache";        $error=$http->Open($arguments);        if($error=="")        {            $error=$http->SendRequest($arguments);            if($error=="")            {                $headers=array();                $error=$http->ReadReplyHeaders($headers);                if($error=="")                {                    # get file size                    /*foreach($headers as  $header_name => $header_value)			        {                        ($hook = YABPlugin::fetch_hook('geturlfile_check_httpheader',__FILE__,__LINE__)) ? eval($hook) : '';			    		if($header_name=='content-length')			    		{                            $filesize=$header_value;                            $tmpfile['size']     = $filesize;                            if(!$this->checkFile($tmpfile)) return $tmpfile;                            break;			    		}			    	}*/                    if($http->content_length_set==1)                    {                        $filesize=$http->content_length;                        $tmpfile['size'] = $filesize;                    }                    # get the exact file info                    $filename=basename($http->request_uri);                    $filetype=getExt($filename);                    $tmpfile['name']=$filename;                    # check file limitions                    if(!$this->checkFile($tmpfile))                    {                        $tmpfile['error'] = 1;                        return $tmpfile;                    }                    # set progress bar info                    $dtstart = $this->upload_start;                    $iTotal  = $this->progbar=='single' ? $filesize : $this->total_size;                    $iRead   = $this->progbar=='single' ? 0 : $this->uploaded_size;                    # record filesize into $flength_name                    if($this->progtype=='ajax'&&$this->progbar=='single')                    {                        $fp2=fopen($this->temp_dir.'/'.$monitor_file,'wb');                        fwrite($fp2,$iTotal);                        fclose($fp2);                    }                                        # create temporary file                    $fp=fopen($this->temp_dir.'/'.$data_file,'wb');                    $tmpfile['tmp_name'] = $this->temp_dir.'/'.$data_file;                    # and downloading file                    for($i=0;;)  		            {                        # read response body                        $error=$http->ReadReplyBody($body,4096);                        if($error!="")                        {                            $http->Close();                            fclose($fp);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -