Home >Backend Development >PHP Tutorial >PHP file upload with progress bar (1/3)_PHP tutorial

PHP file upload with progress bar (1/3)_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:08:071064browse

Implementation
Generally speaking, there are two methods to implement upload progress bar using php tutorial:
1.apc extension (the author is the founder of php tutorial, php has added apc extension after 5.2)
2.pecl extension module uploadprogress
Whether it is apc or uploadprogress, you need to compile the source code tutorial, because the original php function cannot read the contents of the temporary folder. Let’s take a look at how to use it and the key code: apc implementation method:
1. Install apc
2. Configure php.ini and set the parameter apc.rfc1867=1
3. Key code:

if ($_server['request_method'] == 'post') { //Upload request
$status = apc_fetch('upload_' . $_post['apc_upload_progress']);
$ status['done'] = 1;
echo json_encode($status); //Output to the ajax call in the client page, please find relevant documents yourself
exit;
} elseif (isset($ _get['progress_key'])) { //Read upload progress
$status = apc_fetch('upload_'.$_get['progress_key']);
echo json_encode($status);
exit ;
}

Uploadprogress implementation method:
1. Use pecl to install uploadprogress
2. Set uploadprogress.file.filename_template = “/tmp/upd_%s in php.ini .txt"
3. Key code:

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
}
}

1 2 3

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444914.htmlTechArticleTo implement the general situation, there are two methods to use the PHP tutorial to implement the upload progress bar: 1. apc extension (author Is the founder of php tutorial, php has added apc extension after 5.2) 2.pecl extension module...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn