Configure and use swfupload. Swfupload is a component used for file upload. we think it is very good for large files. let's introduce the configuration and usage of swfupload. Swfupload is a component used for uploading large files. we think swfupload is a good component for uploading large files. let's introduce how to configure and use swfupload.
Swfupload is easy to use for uploading large files. the following uses the classic form demo as an example to describe how to use it.
: Http://code.google.com/p/swfupload/downloads/list
SWFUpload_v250_beta_3_samples.zip is the instance code, decompress it, rename it as swfupload, and save it to the local directory (nginx + php environment ).
Http: // localhost/swfupload/demos/access
There are two folders, demos is the client instance, and samples provides file saving code in various languages.
Switch to http: // localhost/swfupload/demos/formsdemo/normal form mode
Create a folder named uploads under/demos/formsdemo /.
Copy the code in/smaples/php/upload. php to the beginning of/demos/formsdemo/upload. php, that is
// The Demos don't save files
Below is a comment.
Modify
| The code is as follows: |
|
|
View sourceprint? $ Upload_name = "filedata ";
Is:
View sourceprint? $ Upload_name = "resume_file "; |
(Consistent with the form element name in/demos/formsdemo/index. php)
In this case, you can use the form to normally upload files. the uploaded files are stored in the/demos/formsdemo/uploads/directory.
In the database processing section, modify the following code:
| The code is as follows: |
|
|
If (isset ($ _ FILES ["resume_file"]) & is_uploaded_file ($ _ FILES ["resume_file"] ["tmp_name"]) & $ _ FILES ["resume_file"] ["error"] = 0 ){
Echo rand (1000000,999 9999); // Create a pretend file id, this might have come from a database.
} |
This code is the upload in the original demo. when it is used, it returns the id of an uploaded file and assigns it to the hidFileID tag of the form (note that this tag is a hidden element)
The original demo is a random number, which is the id value of a database table to be modified to the database insert operation. That is, the following practices:
Remove the if judgment on $ _ FILES (is_uploaded_file after move_uploaded_file above is determined to be false), insert the database, and directly echo the obtained id (number type ).
For uploading large files, you must first modify
| The code is as follows: |
|
|
/Demos/formsdemo/index. php
View sourceprint? File_size_limit: "100 MB ", |
Change to the expected size (up to 2 GB)
Modify nginx. conf,/etc/init. d/nginx reload. if the following settings are not added, nginx will encounter the 413 Request Entity Too Large error.
| The code is as follows: |
|
|
View sourceprint? Http {
...
Client_max_body_size 128 M
...
} |
You also need to modify the server configuration php. ini,/etc/init. d/php-cgi reload
| The code is as follows: |
|
|
View sourceprint? Upload_max_filesize 100 M
Post_max_size 100 M
Memory_limit 128 M |
Note that swfupload does not require you to modify the configuration of max_execution_time and max_input_time.
Bytes. Swfupload for uploading large files...