File Upload progress bar php code this article uses a php plug-in instance mail php File Upload progress bar function, the method is relatively simple, because there are components, as long as you follow the instructions of others, you can use the php large file upload function.
Php tutorial code for file upload progress bar
This article uses the php plug-in instance mail php File Upload progress bar function, the method is relatively simple, because there are components, as long as you follow the instructions of others, you can use the php large file upload function.
Currently, I know two methods: one is to use the apc extension module written by rasmus lerdorf, founder of php to implement (http://pecl.php.net/package/apc ), another way is to use the pecl extension module uploadprogress implementation (http://pecl.php.net/package/uploadprogress) I here are two examples of implementation respectively for reference, more flexible application according to their own needs to modify.
Apc implementation method:
Install apc by referring to the official documentation. You can use the pecl module to install apc quickly and easily.
Configure php. ini and set the parameter apc. rfc1867 = 1 to enable apc to support the upload progress bar function, which is described in the apc source code instructions.
Php File Upload progress bar implementation method: Install apc, refer to the official documentation for installation, you can use the pecl module installation method is quick and simple, it is not described here to configure php. ini, set the apc parameter. rfc1867 = 1 to enable apc to support the upload progress bar function. The following code examples are provided in the apc source code instructions:
If ($ _ server ['request _ method'] = 'post') {// upload request
$ Status = apc_fetch ('upload _ '. $ _ post ['apc _ upload_progress']);
$ Status ['done'] = 1;
Echojson_encode ($ status); // ajax call output to the user's page. Please find the relevant documentation.
Exit;
} Elseif (isset ($ _ get ['ss SS _ key']) {// read the upload progress
$ Status = apc_fetch ('upload _ '. $ _ get ['ss SS _ key']);
Echojson_encode ($ status );
Exit;
} Else {
// Other code, such as uploading a form
}
Uploadprogress module implementation method: Use the pecl module Installation Method to install the php file Upload progress bar of this module implementation method set uploadprogress. file. filename_template = "/tmp/upd_%s.txt" in php. ini"
If ($ _ server ['request _ method'] = 'post '){
If (is_uploaded_file ($ _ files ['upfile'] ['tmp _ name']) {
$ Upload_dir = 'your _ path /';
$ Ext = strrchr ($ _ files ['video'] ['name'], '.');
$ Sessid = $ _ post ['upload _ identifier '];
$ Tmpfile = $ upload_dir. $ sessid;
$ Sessfile = $ upload_dir. $ sessid. $ ext;
If (move_uploaded_file ($ _ files ['upfile'] ['tmp _ name'], $ tmpfile )){
// Upload successful
} Else {
// Upload Failed
} Else {
// Upload Error
} Elseif (! Empty ($ _ get ['sessid ']) {
Header ("expires: mon, 26jul199705: 00: 00gmt ");
Header ("last-modified:". gmdate ("d, dmyh: I: s"). "gmt ");
Header ("cache-control: no-store, no-cache, must-revalidate ");
Header ("cache-control: post-check = 0, pre-check = 0', false );
Header ("pragma: no-cache ");
Header ("content-type: text/html; charset = UTF-8 ′);
$ Unique_id = $ _ get ['sessid'];
$ Uploadvalues = uploadprogress_get_info ($ unique_id );
If (is_array ($ uploadvalues )){
Echo json_encode ($ uploadvalues );
} Else {
// Read progress failed. Additional processing logic
}
} Else {
// Display the upload form
}
The uploadprogress Implementation of the pecl extension module.
Analysis of php-based ajax technology
Php specific solution to limit the size of uploaded files
Implementation of php batch upload of images
Php dynamic multi-file upload code sharing
For details about the php generic File Upload class, here are two implementation examples for your reference. More flexible applications can be modified as needed.
Implementation of the PHP File Upload progress bar of apc:
Install apc by referring to the official documentation. You can use the pecl module to install apc quickly and easily.