File Upload swfupload plugin (code), File upload swfupload_php tutorial

Source: Internet
Author: User

File Upload swfupload plugin (code), file upload swfupload


Below through a piece of code to show you, mainly divided into 1. foreground files index.html and 2. background file upload.php. The specific code looks like this:

1. Front Desk file index.html 
 
  SWFUpload
 
  
 
  
 
  

SWFUpload

v2.2.0 hanization by LEO.C,

2. background file upload.php

 <?php//Pass Session value (due to flash is incompatible with session, can only be obtained by parameter pass) if (Isset ($_post["PHPSESSID"])) {session_id ($_post["Phpsessid "]); }  else if (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 '? 1024x768: ($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"); Allow file type $valid _chars_regex = '.   A-z0-9_!@#$%^& () +={}\[\]\ ', ~ '-'; File name rule//other variable $MAX _filename_length = 260; $file _name = ""; $file _extension = ""; $uploaderrors = Array (0=> "file upload succeeded", 1=> "uploaded file exceeded upload_max_filesize directive settings in php.ini file", 2=> "uploaded file exceeded HTML form file in the max_file_size Directive settings ", 3=>" uploaded files only part of the file ", 4=>" no file Upload ", 6=>" Missing temporary folder "); Detects if the file is uploaded correctly if (!isset ($_files[$upload _name])) {HandleError ("No upload found in \$_files for".  $upload _name); Exit (0); } else if (Isset ($_files[$upload _name]["error"]) && $_files[$upload _name]["Error"]! = 0) {HandleError ($  uploaderrors[$_files[$upload _name]["error"]); Exit (0);  } else if (!isset ($_files[$upload _name]["Tmp_name"]) | |! @is_uploaded_file ($_files[$upload _name]["Tmp_name"])) {  HandleError ("Upload failed is_uploaded_file test."); Exit (0);  } else if (!isset ($_files[$upload _name][' name ')) {HandleError ("File has no name."); Exit (0); }//Detect 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); }//Detection 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 name file if (file_exists ($save _path. $file _name)) {HandleError ("file with this name already exists"); Exit (0); }//detection suffix $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 file if (! @move_uploaded_file ($_files[$upload _name]["Tmp_name"], $save _path. $file _name)) {HandleError ("file cannot be saved."); Exit (0); }//Successfully output echo "File Received"; Exit (0); function HandlEerror ($message) {header ("http/1.1 Internal Server Error"); echo $message;}? >

The above code is the implementation of the file upload swfupload plug-in all the content, I hope you like.

http://www.bkjia.com/PHPjc/1040816.html www.bkjia.com true http://www.bkjia.com/PHPjc/1040816.html techarticle File Upload swfupload plugin (code), file upload swfupload below through a section of code to show you, mainly divided into 1. foreground files index.html and 2. background file upload.php. ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.