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

📄 upload.class.php

📁 网络硬盘_支持1GB文件上传和续传_无错版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
                            $tmpfile['error']    = 1;                            $tmpfile['errinfo']  = 'Remote file error';                            return $tmpfile;                        }                                                # read size                        $readlength=strlen($body);                        $iRead +=$readlength;                                                # progress bar                        # if($this->progtype=='syn'&&$i%100==0) sleep(1);                        if($this->progtype=='syn'&&$readlength==0)                        {                            //showProgStatus($iTotal,$iRead,$dtstart,&$dtRemainingf,&$dtelapsedf,&$bSpeedf,&$percent);                            showStatus($iTotal,$iRead,$dtstart);                            break;                        }                        elseif($i%5==0)                        {                            $this->writeContents($this->temp_dir.'/'.$progress_file, $iRead);                        }                                                if($readlength==0) break;                        # write response contents to temporary file                        fwrite($fp,$body);                        # progress bar                        if($this->progtype=='syn'&&$i%5==0)                        {                            showStatus($iTotal,$iRead,$dtstart);                        }                                                # record loops                        $i++;		            }                    fclose($fp);                    # create signal file                    if($this->progtype=='ajax'&&$this->progbar=='single')                    {                        $fp2=fopen($this->temp_dir.'/'.$signal_file,'wb');                        fclose($fp2);                    }                    $tmpfile['error']=0;                }                else                {                    $tmpfile['error']=1;                }	      	}            else            {                $tmpfile['error']=1;            }        }        else        {            $tmpfile['error']=1;        }	    $http->Close();        if($tmpfile['error']==0) $tmpfile['filename'] = $this->tempname($filetype);        return $tmpfile;    }    function getUrlFileSize($uri)    {        $filename=basename($uri);        $filetype=getExt($filename);        # construct the tmpfile        $tmpfile=array('name'=>$filename);        $http = new http_class();        $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)			        {			    		if($header_name=='content-length')			    		{                            $filesize=$header_value;                            $tmpfile['size']     = $filesize;                            if(!$this->checkFile($tmpfile)) return $tmpfile;                            break;			    		}			    	}                }                else                {                    $tmpfile['error']=1;                }	      	}            else            {                $tmpfile['error']=1;            }        }        else        {            $tmpfile['error']=1;        }	    $http->Close();        if($tmpfile['error']==1&&$error) $tmpfile['errinfo']=$error;        return $tmpfile;    }    function getFTPFile($uri)    {        # 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';                $ftp = new ftp();        $ftp->debug = TRUE;        # parse ftp url        $parts=parse_url($uri);        $ftp_host=$parts[host];        $ftp_port=$parts[port]?$parts[port]:'21';        $ftp_user=$parts[user]?$parts[user]:'anonymous';        $ftp_pass=$parts[pass]?$parts[pass]:'anonymous';        $remote_filename=$parts[path];        $filename=basename($uri);        $filetype=getExt($filename);        # construct the tmpfile        $tmpfile=array('name'=>$filename);                # connect to ftp host        if (!$ftp->ftp_connect($ftp_host,$ftp_port))        {            $tmpfile['error']=1;            $tmpfile['errinfo']='Cannot connect';            return $tmpfile;        }        # login with username and password        if (!$ftp->ftp_login($ftp_user, $ftp_pass)) {    	    $ftp->ftp_quit();            $tmpfile['error']=1;            $tmpfile['errinfo']='Login failed';            return $tmpfile;        }        # get file size        $filesize = $ftp->ftp_size($remote_filename);        if($filesize == -1)        {            $tmpfile['error']=1;            $tmpfile['errinfo']='Could not get file size';            return $tmpfile;        }        else        {            $tmpfile['size']=$filesize;        }        # check file by us        if(!$this->checkFile($tmpfile)) return $tmpfile;        # create temporary file        # $stored_name=mytempname($this->temp_dir, '', $filetype);        $tmpfile['tmp_name'] = $this->temp_dir.'/'.$data_file;        $fp=fopen($tmpfile['tmp_name'],'wb');                $iTotal  = $filesize;        $iTotal  = $this->progbar=='single' ? $filesize : $this->total_size;        # assign var to ftp calss        $ftp->total_size    = $iTotal;        $ftp->progtype      = $this->progtype;        $ftp->progress_file = $this->temp_dir.'/'.$progress_file;                # record filesize into $flength_name        if($this->progtype=='ajax')        {            $fp2=fopen($this->temp_dir.'/'.$monitor_file,'wb');            fwrite($fp2,$iTotal);            fclose($fp2);        }        # downloading the file        if (!$ftp->ftp_get($tmpfile['tmp_name'],$remote_filename))        {    	    $ftp->ftp_quit();            $tmpfile['error']=1;            $tmpfile['errinfo']='Download error';            return $tmpfile;        }                # create signal file        if($this->progtype=='ajax'&&$this->progbar=='single')        {            $fp2=fopen($this->temp_dir.'/'.$signal_file,'wb');            fclose($fp2);        }                            $ftp->ftp_quit();        if($tmpfile['error']==0) $tmpfile['filename'] = $this->tempname($filetype);        return $tmpfile;    }    function getFTPFileSize($uri)    {        $ftp = new ftp();        $ftp->debug = TRUE;        # parse ftp url        $parts=parse_url($uri);        $ftp_host=$parts[host];        $ftp_port=$parts[port]?$parts[port]:'21';        $ftp_user=$parts[user]?$parts[user]:'anonymous';        $ftp_pass=$parts[pass]?$parts[pass]:'anonymous';        $remote_filename=$parts[path];        $filename=basename($uri);        $filetype=getExt($filename);        # construct the tmpfile        $tmpfile=array('name'=>$filename);        # connect to ftp host        if (!$ftp->ftp_connect($ftp_host,$ftp_port))        {            $tmpfile['error']=1;            $tmpfile['errinfo']='Cannot connect';            return $tmpfile;        }        # login with username and password        if (!$ftp->ftp_login($ftp_user, $ftp_pass)) {    	    $ftp->ftp_quit();            $tmpfile['error']=1;            $tmpfile['errinfo']='Login failed';            return $tmpfile;        }        # get file size        $filesize = $ftp->ftp_size($remote_filename);        if($filesize == -1)        {            $tmpfile['error']=1;            $tmpfile['errinfo']='Could not get file size';            return $tmpfile;        }        else        {            $tmpfile['size']=$filesize;        }        # check file by us        if(!$this->checkFile($tmpfile)) return $tmpfile;                return $tmpfile;    }    function getLocalFile($file)    {        $filetype=getExt($file['name']);        # check file by us        $this->checkFile($file);        $file['filename'] = $this->tempname($filetype);        return $file;    }    function tempname($filetype)    {        # format: 7 chars name + server id + ext        # return mytempname($this->upload_dir, '', $this->server_id) . (!$this->keep_ext?'_':'.') . $filetype;        # format: 8 chars name + .server id + ext        return mytempname($this->upload_dir) . '.' . $this->server_id . (!$this->keep_ext?'_':'.') . $filetype;        # format: unqiue server id + 7 chars name +  ext        return mytempname($this->upload_dir, $this->server_id) . (!$this->keep_ext?'_':'.') . $filetype;        # format: server id + 7 chars name +  ext        return mytempname($this->upload_dir, $this->server_id, (!$this->keep_ext?'_':'.').$filetype);        # format: 8 chars name +  ext        return mytempname($this->upload_dir, '', (!$this->keep_ext?'_':'.').$filetype);    }    function writeContents($filename, $contents)    {        $fwriteHandle = @fopen($filename, "w");        if (!is_resource($fwriteHandle))        {            return false;        }        fwrite($fwriteHandle, $contents);        fclose($fwriteHandle);        return true;    }    /**    *5:store infomation in db:make the uplaod time is unique by "fake" uploadtime    */    function InsertDB($file,$extras=array())    {    global $db,$user,$input;        # get upload ip        $upload_ip = $input[uploadmode]!=1?$input[IP_CLIENT]:$input[IP_CGI];        $upload_ip = empty($input[IP_CGI])?$input[IP_CLIENT]:$input[IP_CGI];        # generate unique upload id and delete id        $upload_id = strtoupper($this->getUploadID($file[filename]));        $delete_id = strtoupper(substr(md5(microtime()), 0, 4));        # prepare data        $filetable = new TABLE($db,'files','id');        $filetable->time        = $this->upload_time;        $filetable->server_id   = $this->server_id;        $filetable->upload_session  = $this->upload_session;        $filetable->uid         = $this->uploader_id;        $filetable->password    = $user->dl_password==1?$extras[password]:'';        $filetable->descr       = $extras[descr];                $filetable->ip          = $upload_ip;        $filetable->file        = $file[filename];        $filetable->size        = $file[size];        $filetable->name        = $file[name];                $filetable->upload_id   = $upload_id;        $filetable->delete_id   = $delete_id;                # inserting        $filetable->insert();        # increase upload time to avoid repeat one!        $this->upload_time++;        $filetable->id = $filetable->insertid();        return $filetable;    }    function getUploadID($filename)    {    global $db;        return substr($filename,0,8).$this->server_id;        // Create the upload id	    do {		    $upload_id = substr(md5(microtime()), 0, 8);            $db->setQuery("select * from files where upload_id='$upload_id' limit 1");            $db->query();            $exists = $db->getNumRows();	    } while ($exists);	    return $upload_id;    }    function getUploadID2($filename)    {    global $db;        return substr($filename,0,8).$this->server_id;        // Create the upload id	    do {		    $upload_id = substr(md5(microtime()), 0, 8);            $db->setQuery("select * from files where upload_id='$upload_id' limit 1");            $db->query();            $exists = $db->getNumRows();	    } while ($exists);	    return $upload_id;    }    function setError($err)    {        echo $err;        $this->upload_errors .= $err."\n";    }}?>

⌨️ 快捷键说明

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