Use the SWFUpload plug-in to upload files

Source: Internet
Author: User
: This article describes how to use the SWFUpload plug-in to upload files. if you are interested in the PHP Tutorial, refer to it. The demo code consists of two parts, including foreground and background files:

1.front file index.html

 SWFUpload
 
 
 

SWFUpload

V2.2.0

Click "browse" and select the document file to be uploaded. The system will automatically upload the file and prompt you after it is complete.

Do not upload files containing Chinese file names!

Quick Upload

0 files uploaded

Hanization By Leo. C,


2. background file upload. php

 $ Multiplier * (int) $ POST_MAX_SIZE & $ POST_MAX_SIZE) {header ("HTTP/1.1 500 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; // 2 GB $ extension_whitelist = array ("doc", "txt ", "jpg", "gif", "png"); // allows the file type $ valid_chars_regex = '. a-Z0-9 _! @ # $ % ^ & () + ={}\ [\] \ ', ~ '-'; // File name rules // Other variables $ MAX_FILENAME_LENGTH = 260; $ file_name = ""; $ file_extension = ""; $ uploadErrors = array (0 => "file uploaded successfully", 1 => "the uploaded file exceeds php. the setting in upload_max_filesize directive in the ini file ", 2 =>" the uploaded file exceeds the setting in MAX_FILE_SIZE directive in the HTML form File ", 3 => "only part of the uploaded file", 4 => "No file upload", 6 => "temporary folder missing "); // check whether the file is uploaded correctly if (! Isset ($ _ FILES [$ upload_name]) {HandleError ("No upload found in \ $ _ FILES ". $ 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);} // check the 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);} // The detection File name is blank $ 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);} // checks if (file_exists ($ save_path. $ file_name) {HandleError ("File with this name already exists"); exit (0 );} // Check the suffix $ path_info = pathinfo ($ _ FILES [$ upload_name] ['name']); $ file_extension = $ path_info ["extension"]; $ is_valid_extension = false; foreach ($ extension_whitelistas $ extension) {if (strcasecmp ($ file_extension, $ extension) = 0) {$ is_valid _ Extension = true; break ;}} if (! $ Is_valid_extension) {HandleError ("Invalid file extension"); exit (0) ;}// save the file if (! @ Move_uploaded_file ($ _ FILES [$ upload_name] ["tmp_name"], $ save_path. $ file_name) {HandleError ("the file cannot be saved. "); exit (0);} // echo" File already ed "is successfully output; exit (0 );
Function HandleError ($ message) {header ("HTTP/1.1 500 Internal Server Error"); echo $ message;}?>

The above describes how to use the SWFUpload plug-in to upload files, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.