Home  >  Article  >  Backend Development  >  swfupload configuration and usage_PHP tutorial

swfupload configuration and usage_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:11:36887browse

swfupload is a component used for file upload. We think it is very good for large files. Let me introduce the configuration and use of swfupload.

swfupload is easy to use for uploading large files. Let’s take the classic form demo as an example to briefly explain the usage.

Download address: http://code.google.com/p/swfupload/downloads/ list

Among them, SWFUpload_v250_beta_3_samples.zip is the example code. After decompression, rename it to swfupload and save it to the local main folder (nginx+php environment). You can then use

http://localhost /swfupload/demos/ Access two folders in

. demos is an instance of the client, and samples provides file saving codes in each language.

Switch to http://localhost/swfupload/demos/formsdemo/, which is the normal form mode

Create a new folder uploads under /demos/formsdemo/

Change /smaples Copy the code in /php/upload.php to the beginning of /demos/formsdemo/upload.php, that is,

// The Demos don't save files

below the comment.

Modify

The code is as follows Copy code
 代码如下 复制代码

view sourceprint?$upload_name = "filedata";

为:

view sourceprint?$upload_name = "resume_file";

view sourceprint?$upload_name = "filedata";

is:

view sourceprint?$upload_name = " resume_file";

(Same as the form element name in /demos/formsdemo/index.php)

At this point, you can use the form Upload files normally. The uploaded files are saved in the /demos/formsdemo/uploads/ directory
 代码如下 复制代码

if (isset($_FILES["resume_file"]) && is_uploaded_file($_FILES["resume_file"]["tmp_name"]) && $_FILES["resume_file"]["error"] == 0) { 

    echo rand(1000000, 9999999);    // Create a pretend file id, this might have come from a database. 

}

In the database processing part, the following code should be modified:

The code is as follows Copy code

if (isset($_FILES["resume_file"]) && is_uploaded_file($_FILES["resume_file"]["tmp_name"]) && $_FILES["resume_file"]["error"] == 0) {

echo rand(1000000, 9999999); // Create a pretend file id, this might have come from a database.

 代码如下 复制代码

/demos/formsdemo/index.php中

view sourceprint?file_size_limit : "100 MB",

}

This code is the upload in the original demo. Its function 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 random The generated number should be modified here to be the ID value of a database table obtained by the database insertion operation. That is, the following approach:
 代码如下 复制代码

view sourceprint?http { 

... 

client_max_body_size 128M 

... 

}

Remove the if judgment on $_FILES (this is_uploaded_file is judged to be false after the move_uploaded_file above); perform database insertion operation; directly echo the obtained id (numeric type). For large file uploads, you need to modify the form part first, that is,
The code is as follows Copy code
/demos/formsdemo/index.php in view sourceprint?file_size_limit: " 100 MB",
Modify to the expected size (maximum 2G)Modify nginx.conf, /etc/init.d/nginx reload, if you do not add the following settings, nginx will have a 413 Request Entity Too Large error
The code is as follows Copy code
view sourceprint?http { ... client_max_body_size 128M ... }

At the same time, you need to modify the server configuration php.ini, /etc/init.d/php-cgi reload

view sourceprint?upload_max_filesize 100M
The code is as follows
 代码如下 复制代码

view sourceprint?upload_max_filesize 100M 

post_max_size 100M 

memory_limit 128M

Copy code

post_max_size 100M
memory_limit 128M

Note that swfupload does not require modification of the configuration of max_execution_time and max_input_time. http://www.bkjia.com/PHPjc/444644.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/444644.htmlTechArticleswfupload is a component used for file upload. We think it is very good for large files. Let me introduce it below. How to configure and use swfupload. swfupload is equal to uploading large files...
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