The demo code consists of two parts, including the foreground file and the background file:
1. Front desk file index.html
DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312"/><Head><title>SWFUpload
title><Linkhref= "Css/default.css"rel= "stylesheet"type= "Text/css"/>
<Scripttype= "Text/javascript"src= "Swfupload/swfupload.js">
Script><Scripttype= "Text/javascript"src= "Js/swfupload.queue.js">
Script><Scripttype= "Text/javascript"src= "Js/fileprogress.js">
Script><Scripttype= "Text/javascript"src= "Js/handlers.js">
Script>
<Scripttype= "Text/javascript">varswfu; window.onload=function() { varSettings={flash_url:"swfupload/swfupload.swf", Upload_url:"upload.php", //Background Filespost_params: {"Phpsessid" : "
"}, File_size_limit:"MB", File_Types:"*.*", file_types_description:"All Files", File_upload_limit: -, File_queue_limit:0, custom_settings: {progresstarget:"fsuploadprogress", Cancelbuttonid:"Btncancel"}, Debug:false, //button SettingsButton_image_url:"Images/testimagenotext_65x29.png", //Flash style picture fileButton_width:" $", Button_height:" in", button_placeholder_id:"Spanbuttonplaceholder", Button_text:'Browse', Button_text_style:". Thefont {font-size:16;}", button_text_left_padding: A, button_text_top_padding:3, //Handle Settingsfile_queued_handler:filequeued, File_queue_error_handler:filequeueerror, File_dialog_complete_handler: Filedialogcomplete, Upload_start_handler:uploadstart, upload_progress_handler:uploadprogress, Upload_error_ Handler:uploaderror, Upload_success_handler:uploadsuccess, Upload_complete_handler:uploadcomplete, Queue_complete _handler:queuecomplete}; Swfu=Newswfupload (settings);};
Script>
Head><Body><DivID= "header"><H1ID= "logo"><ahref="/">SWFUpload
a>
H1><DivID= "Version">v2.2.0
Div>
Div><DivID= "Content"><formID= "Form1"Action= "index.php"Method= "POST"enctype= "Multipart/form-data"><P>Click "Browse" button, select the document file you want to upload, the system will automatically upload and prompt you after completion.
P><P>Do not upload files that contain Chinese filenames!
P><Divclass= "FieldSet Flash"ID= "Fsuploadprogress"><spanclass= "Legend">Fast Upload
span>
Div><DivID= "Divstatus">0 files Uploaded
Div><Div><spanID= "Spanbuttonplaceholder">
span><inputID= "Btncancel"type= "button"value= "Cancel all uploads"onclick= "Swfu.cancelqueue ();"Disabled= "Disabled"style= "margin-left:2px; font-size:8pt; height:29px;"/>
div>
form>
div> < Div Align = "Center" > Hanization by <a href= "Http://imll.net" target= "_ Blank ">leo.c,
a>
div>
body>
html>
2. background file upload.php
Php//Pass Session value (due to flash not compatible with session, can only be obtained by parameter passing)if(isset($_post["Phpsessid"])) { session_id($_post["Phpsessid"]); } Elseif(isset($_get["Phpsessid"])) { session_id($_get["Phpsessid"]); } Session_Start();//set post maximum value$POST _max_size=Ini_get(' Post_max_size '); $unit=Strtoupper(substr($POST _max_size,-1)); $multiplier= ($unit= = ' M '? 1048576: ($unit= = ' K '? 1024: ($unit= = ' G '? 1,073,741,824:1))); if((int)$_server[' Content_length '] >$multiplier* (int)$POST _max_size&&$POST _max_size) { Header("http/1.1 Internal Server Error"); Echo"POST exceeded maximum allowed size."; Exit(0); }//Basic Settings$save _path=GETCWD() . "/file/";//File Upload location$upload _name= "Filedata"; $max _file_size_in_bytes= 2147483647;//2GB$extension _whitelist=Array("Doc", "txt", "jpg", "gif", "PNG");//allowed file Types$valid _chars_regex= '. A-z0-9_!@#$%^& () +={}\[\]\ ', ~ '-';//file name rules//other variables$MAX _filename_length= 260; $file _name= ""; $file _extension= ""; $uploadErrors=Array( 0=> "File Upload succeeded", 1=> "uploaded file exceeds the settings in upload_max_filesize directive in php.ini file", 2=> "uploaded file exceeds HTML form Files in the max_file_size Directive settings ", 3=>" uploaded files only part of the file ", 4=>" no file Upload ", 6=>" Missing Temp folder " );//detects if the file is uploaded correctlyif(!isset($_files[$upload _name]) {HandleError ("No upload found in \$_files for".$upload _name); Exit(0); } Elseif(isset($_files[$upload _name["Error"]) &&$_files[$upload _name["Error"]! = 0) {HandleError ($uploadErrors[$_files[$upload _name["Error"]]); Exit(0); } Elseif(!isset($_files[$upload _name["Tmp_name"]) | | !@Is_uploaded_file($_files[$upload _name["Tmp_name"]) {HandleError ("Upload failed is_uploaded_file test."); Exit(0); } Elseif(!isset($_files[$upload _name[' Name ']) {HandleError ("File has no name."); Exit(0); } //detection file size$file _size= @filesize($_files[$upload _name["Tmp_name"]); if(!$file _size||$file _size>$max _file_size_in_bytes) {HandleError ("File exceeds the maximum allowed size"); Exit(0); } if($file _size<= 0) {HandleError ("File size outside allowed lower bound"); Exit(0); }//test file name is empty$file _name=Preg_replace('/[^'.$valid _chars_regex.']| \.+$/i ', "",basename($_files[$upload _name[' Name '])); if(strlen($file _name) = = 0 | |strlen($file _name) >$MAX _filename_length) {HandleError ("Invalid file name"); Exit(0); }//Detect duplicate Filesif(file_exists($save _path.$file _name) {HandleError ("File with this name already exists"); Exit(0); }//Detecting suffix names$path _info=PathInfo($_files[$upload _name[' Name ']); $file _extension=$path _info["Extension"]; $is _valid_extension=false; foreach($extension _whitelist as$extension) { if(strcasecmp($file _extension,$extension) = = 0) { $is _valid_extension=true; Break; } } if(!$is _valid_extension) {HandleError ("Invalid file extension"); Exit(0); }//Save Fileif(!@Move_uploaded_file($_files[$upload _name["Tmp_name"],$save _path.$file _name) {HandleError ("The file cannot be saved."); Exit(0); }//Successful outputEcho"File Received"; Exit(0);
functionHandleError ($message) { Header("http/1.1 Internal Server Error"); Echo$message;}?>
The above describes the use of SWFUpload plugin upload files, including aspects of the content, I hope the PHP tutorial interested in a friend helpful.