Table of Contents
SWFUpload" >SWFUpload
SWFObject Demo
Home Backend Development PHP Tutorial PHP swfupload图片文件上传范例代码

PHP swfupload图片文件上传范例代码

Jun 13, 2016 pm 12:20 PM
file gt handler lt

PHP swfupload图片文件上传实例代码

swfupload是一个flash插件它可以结合php来快速实现图片文件无刷新上传,同时还可以批量上传图片,下面我来给大家介绍PHP swfupload图片文件上传实例代码有需要了解的中参考。

效果图



?

index.php文件

<title>SWFUpload Demos - SWFObject Demo</title><link href="../css/default.css" rel="stylesheet" type="text/css"><script type="text/javascript" src="../swfupload/swfupload.js"></script><script type="text/javascript" src="js/swfupload.swfobject.js"></script><script type="text/javascript" src="js/swfupload.queue.js"></script><script type="text/javascript" src="js/fileprogress.js"></script><script type="text/javascript" src="js/handlers.js"></script><script type="text/javascript">var swfu;SWFUpload.onload = function () { var settings = {  flash_url : "../swfupload/swfupload.swf",  upload_url: "upload.php",  post_params: {   "PHPSESSID" : "NONE",   "HELLO-WORLD" : "Here I Am",   ".what" : "OKAY"  },  file_size_limit : "100 MB",  file_types : "*.jpg;*.gif;*.png;*.jpeg;",  file_types_description : "All Files",  file_upload_limit : 100,  file_queue_limit : 0,  custom_settings : {   progressTarget : "fsUploadProgress",   cancelButtonId : "btnCancel"  },  debug: false,  // Button Settings  button_image_url : "XPButtonUploadText_61x22.png",  button_placeholder_id : "spanButtonPlaceholder",  button_width: 61,  button_height: 22,  // The event handler functions are defined in handlers.js  swfupload_loaded_handler : swfUploadLoaded,  file_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, // Queue plugin event    // SWFObject settings  minimum_flash_version : "9.0.28",  swfupload_pre_load_handler : swfUploadPreLoad,  swfupload_load_failed_handler : swfUploadLoadFailed }; swfu = new SWFUpload(settings);}</script><div id="header"> <h1 id="a-href-SWFUpload-a"><a href="../">SWFUpload</a></h1> <div id="version">v2.2.0</div>
</div><div id="content"> <h2 id="SWFObject-Demo">SWFObject Demo</h2> <form id="form1" action="index.php" method="post" enctype="multipart/form-data">  <p> This page demonstrates the SWFObject plugin.  Do each of the following (one at a time) to see the plugin work: </p>   <ul>    <li>Uninstall your Flash Player or install a version less than 9.0.28</li>    <li>Cause the SWF file to fail to load by deleting or renaming swfupload.swf (simulating a very slow or failed download)</li>    <li>Disable JavaScript</li>   </ul>  <p>   Each of these tests demontrate how these issues can be handled by SWFUpload and the SWFObject libraries.  </p>  <div id="divSWFUploadUI">   <div class="fieldset  flash" id="fsUploadProgress">   <span class="legend">Upload Queue</span>   </div>   <p id="divStatus">0 Files Uploaded</p>   <p>    <span id="spanButtonPlaceholder"></span>    <input id="btnCancel" type="button" value="Cancel All Uploads" disabled style="margin-left: 2px; height: 22px; font-size: 8pt;">    <br>   </p>  </div>  <noscript>   <div style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px;">    We're sorry.  SWFUpload could not load.  You must have JavaScript enabled to enjoy SWFUpload.   </div>  </noscript>  <div id="divLoadingContent" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">   SWFUpload is loading. Please wait a moment...  </div>  <div id="divLongLoading" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">   SWFUpload is taking a long time to load or the load has failed.  Please make sure that the Flash Plugin is enabled and that a working version of the Adobe Flash Player is installed.  </div>  <div id="divAlternateContent" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">     </div> </form>
</div>
Copy after login

?

核心处理程序php代码

if (isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {    $upload_file = $_FILES['Filedata'];    $file_info   = pathinfo($upload_file['name']);    $file_type   = $file_info['extension'];    $save        = 'image/' . md5(uniqid($_FILES["Filedata"]['name'])) . '.' . $file_info['extension'];    $name        = $_FILES['Filedata']['tmp_name'];     if (!move_uploaded_file($name, $save)) {        exit;    }     //将数组的输出存起来以供查看    $fileName = 'test.txt';    $postData = var_export($file_info, true);    $file     = fopen('' . $fileName, "w");    fwrite($file,$postData);    fclose($file);}
Copy after login

?

swfUpload注意事项

swfuplaod在上传时,会新开一个进程,和原来的进程不一致,要解决这个问题,需要指定session_id,然后在登录页面判断,如果有 post过来的session_id,那么就用函数session_id( $_POST['PHP_SESSIONID'])指定一下。

上传页的JS里面,可以获取当前的SESSION_ID的。

例如上传页的JS中:

post_params: {"PHPSESSID": "<?php echo session_id(); ?>"},
Copy after login

?

在验证的判断页中:

         if (isset($_POST["PHPSESSID"])) {            session_id($_POST["PHPSESSID"]);        }
Copy after login

?

(这一段是网上的注释:在带有Session验证的网站后台中SWFUpload无法正常工作,这是因为SWFUpload在上传时相当于重新开辟了一个 新的Session 进程,因此无法与原有程序的Session保持一致,这就需要在上传时传递原有程序的SessionID,根据它来“找回”其应有的Session。)

DEMO下载地址:http://dl.iteye.com/topics/download/b6351ce4-b3e3-30a3-b8af-eda7b98a1c79

?

?

?

?

?

?

?

?

?

?

?

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

Hongmeng native application random poetry Hongmeng native application random poetry Feb 19, 2024 pm 01:36 PM

To learn more about open source, please visit: 51CTO Hongmeng Developer Community https://ost.51cto.com Running environment DAYU200:4.0.10.16SDK: 4.0.10.15IDE: 4.0.600 1. To create an application, click File- >newFile->CreateProgect. Select template: [OpenHarmony] EmptyAbility: Fill in the project name, shici, application package name com.nut.shici, and application storage location XXX (no Chinese, special characters, or spaces). CompileSDK10, Model: Stage. Device

How to convert php blob to file How to convert php blob to file Mar 16, 2023 am 10:47 AM

How to convert php blob to file: 1. Create a php sample file; 2. Through "function blobToFile(blob) {return new File([blob], 'screenshot.png', { type: 'image/jpeg' })} ” method can be used to convert Blob to File.

Rename files using java's File.renameTo() function Rename files using java's File.renameTo() function Jul 25, 2023 pm 03:45 PM

Use Java's File.renameTo() function to rename files. In Java programming, we often need to rename files. Java provides the File class to handle file operations, and its renameTo() function can easily rename files. This article will introduce how to use Java's File.renameTo() function to rename files and provide corresponding code examples. The File.renameTo() function is a method of the File class.

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Use java's File.getParent() function to get the parent path of the file Use java's File.getParent() function to get the parent path of the file Jul 24, 2023 pm 01:40 PM

Use java's File.getParent() function to get the parent path of a file. In Java programming, we often need to operate files and folders. Sometimes, we need to get the parent path of a file, which is the path of the folder where the file is located. Java's File class provides the getParent() method to obtain the parent path of a file or folder. The File class is Java's abstract representation of files and folders. It provides a series of methods for operating files and folders. Among them, get

Use java's File.getParentFile() function to get the parent directory of the file Use java's File.getParentFile() function to get the parent directory of the file Jul 27, 2023 am 11:45 AM

Use java's File.getParentFile() function to get the parent directory of a file. In Java programming, we often need to operate files and folders. When we need to get the parent directory of a file, we can use the File.getParentFile() function provided by Java. This article explains how to use this function and provides code examples. File class in Java is the main class used to operate files and folders. It provides many methods to obtain and manipulate file properties

See all articles