Implementation
Generally, the following two methods are used to implement the upload progress bar through the php Tutorial:
1. apc extension (The author is the founder of the php Tutorial, and php has joined apc extension since 5.2)
2. pecl extension module uploadprogress
Both apc and uploadprogress need to compile the source code tutorial, because the original php function cannot read anything in the temporary folder. The following describes how to use and the key code: apc implementation method:
1. Install apc
2. Configure php. ini and set the apc. rfc1867 parameter to 1.
3. Key code:
The code is as follows: |
Copy code |
If ($ _ server ['request _ method'] = 'post') {// upload request $ Status = apc_fetch ('upload _ '. $ _ post ['apc _ upload_progress']); $ Status ['Done'] = 1; Echo json_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']); Echo json_encode ($ status ); Exit; } |
Uploadprogress implementation method:
1. Use pecl to install uploadprogress
2. Set uploadprogress. file. filename_template = "/tmp/upd_%s.txt" in php. ini"
3. Key code:
The code is as follows: |
Copy 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 } } |