Home >Backend Development >PHP Tutorial >FireFox browser uses Javascript to upload large files_PHP tutorial
This program uses the feature of Firefox 3.x browser to read local files, realizes the function of uploading large files through xmlHttPRequest, and dynamically displays the upload progress during the upload process. With slight modifications and cooperation with the server, many functions such as breakpoint resume transmission can be realized.
This example mainly studies some features of FireFox's file-input node. Other client applications, such as Flash, Silverlight, etc., when implementing client-side large file uploads, are different from this one in terms of data transmission and server-side storage. The ideas in the examples are basically the same.
Note: There seems to be a critical point in file size, but what this critical point is has not yet been confirmed. It is recommended not to use this method to upload files exceeding 100M.
The following is the client javascript code
/*
* Upload button event
*/
function send(fileID){
var sender = new FireFoxFileSender(
) /*
* Upload configuration file
*/
/*< Change according to server specific conditions. IIS6 defaults to 200K
* /
PackageSize: '200000',
/ *
*Trigger the event when an error occurs. Error in the sending process.
🎜> Delete sender;
){
var per = sd.percent();
document.getElementById('Message').
triggered by onreadystatechange event * If there are no other errors during the transmission process, it can basically be determined that the server-side reception is completed
'); }
,
/*
* Just make sure xhr returns readyState == 4 and status == 200
* The sending will continue
* How the server returns the completion information can be customized by changing the code of the receiving data page
* Then make a judgment based on the value of xhr.responseText }
);
sender.send();
}
The following is the server-side php code
Copy code
* - Otherwise Output 0
* This is just an example, and this information is not received on the js side
* Similarly, you can also use methods such as writing feedback information in the header
* The main purpose is to determine whether there are other problems during the upload process
* To ensure that the uploaded file is complete
*/
if(!empty($b64)){
$stream = base64_decode($ b64);
echo strlen($stream);
/*
* Write the file in append mode
* Modify the file save location here
*/
$file = fopen( '' . $fileName , 'a');
if($file)
if(fwrite($file, $stream))
fclose($file);
} else echo '0 ';
Complete client code
Copy code