Php resumable Upload function. Resumable Upload refers to dividing an upload task (a file or a compressed package) into several parts during Upload. each part is uploaded using a thread, next, resumable Upload refers to dividing the upload task (a file or a compressed package) into several parts manually during the upload process. each part is uploaded using a thread, next let's take a look at the php breakpoint resume function implementation method.
Resumable Upload refers to dividing an upload task (a file or a compressed package) into several parts during Upload. each part is uploaded using a thread, next let's take a look at the php breakpoint resume function implementation method.
/**
* Author Yu nshui
* Supports resumable download.
* Instance code:
* $ Down = new SD_DownLoad ();
* $ Down-> Down ('E:/iso/MS. Office2003SP1. CHS. iso ');
**/
Class SD_DownLoad {
/**
* Download start point
*
* @ Access private
* @ Var integer
*/
Private $ mDownStart;
/**
* File size
*
* @ Access private
* @ Var integer
*/
Private $ mFileSize;
/**
* File handle
*
* @ Access private
* @ Var integer
*/
Private $ mFileHandle;
/**
* Full file path
*
* @ Access private
* @ Var string
*/
Private $ mFilePath;
/**
* File name displayed during File Download
*
* @ Access private
* @ Var string
*/
Private $ mFileName;
/**
* Constructor
*
* @ Access public
* @ Return void
**/
Public function _ construct (){
}
/**
* Download
*
* @ Param string $ pFilePath: full file path
* @ Param string the file name displayed when the pFileName file is downloaded. the default value is the actual file name.
* @ Access public
* @ Return void
**/
Public function Down ($ pFilePath, $ pFileName = ''){
$ This-> mFilePath = $ pFilePath;
If (! $ This-> IniFile () $ this-> SendError ();
$ This-> mFileName = empty ($ pFileName )? $ This-> GetFileName (): $ pFileName;
$ This-> IniFile ();
$ This-> SetStart ();
$ This-> SetHeader ();
$ This-> Send ();
}
/**
* Initialize file information
*
* @ Access private
* @ Return boolean
**/
Private function IniFile (){
If (! Is_file ($ this-> mFilePath) return false;
$ This-> mFileHandle = fopen ($ this-> mFilePath, 'RB ');
$ This-> mFileSize = filesize ($ this-> mFilePath );
Return true;
}
/**
* Set the download start point.
*
* @ Access private
* @ Return void
**/
Private function SetStart (){
If (! Empty ($ _ SERVER ['http _ range']) & preg_match ("/^ bytes = ([d]?) -([D]?) $/I ", $ _ SERVER ['http _ range'], $ match )){
If (empty ($ match [1]) $ this-> mDownStart = $ match [1];
Fseek ($ this-> mFileHandle, $ this-> mDownStart );
}
Else {
$ This-> mDownStart = 0;
}
}
/**
* Set the http header
*
* @ Access private
* @ Return void
**/
Private function SetHeader (){
@ Header ("Cache-control: public ");
@ Header ("Pragma: public ");
Header ("Content-Length:". ($ this-> mFileSize-$ this-> mDownStart ));
If ($ this-> mDownStart> 0 ){
@ Header ("HTTP/1.1 206 Partial Content ");
Header ("Content-Ranges: bytes ". $ this-> mDownStart. "-". ($ this-> mFileSize-1 ). "/". $ this-> mFileSize );
}
Else {
Header ("Accept-Ranges: bytes ");
}
@ Header ("Content-Type: application/octet-stream ");
@ Header ("Content-Disposition: attachment; filename =". $ this-> mFileName );
}
/**
* Obtain the file name in the full path.
*
* @ Access private
* @ Return string
**/
Private function GetFileName (){
Return basename ($ this-> mFilePath );
}
/**
* Send data
*
* @ Access private
* @ Return void
**/
Private function Send (){
Fpassthru ($ this-> mFileHandle );
}
/**
* Sending error
*
* @ Access public
* @ Return void
**/
Public function SendError (){
@ Header ("HTTP/1.0 404 Not Found ");
@ Header ("Status: 404 Not Found ");
Exit ();
}
}
?>
A volume (a file or a compressed package) is divided into several parts. each part is uploaded using a thread. next we will...