首页 > 编程 > PHP > 正文

PHP SWFUpload多文件上传处理

2020-03-22 19:09:27
字体:
来源:转载
供稿:网友
  • 由于工作需求,开始study我不是很熟悉的文件上传部份,而且又要大量文件可以批次上传!!

    可以不要一开始就让我头有点痛吗...

    发现了有几套,大约看过之后,我还是比较喜欢与FLASH整合的SWFUpload,操作感觉也很简约顺畅

    我就是爱有时尚感的东东XD

    不过,很多文章都交代得不是很清楚,连官方文件都是含含糊糊

    官方Demo页 http://demo.swfupload.org/v220/index.htm

    于是就著手更改他的范例,来弄成我要的东西

    index.php

    <?phpsession_start(); if (count($_FILES)) {        // Handle degraded form uploads here.  Degraded form uploads are POSTed to index.php.  SWFUpload uploads// are POSTed to upload.php} ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>SWFUpload测试</title><link href="css/default.css" rel="stylesheet" type="text/css" /><script type="text/javascript" src="js/swfupload/swfupload.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 upload1; window.onload = function() {upload1 = new SWFUpload({// Backend Settingsupload_url: "upload.php",  <-- 处理上传动作post_params: {"PHPSESSID" : "<?php echo session_id(); ?>"}, // File Upload Settingsfile_size_limit : "10240",  <--文件上传大小限制 // 10MBfile_types : "*.*",  <-- 上传文件类型file_types_description : "All Files",file_upload_limit : "50",  <--  一次上传数量限制file_queue_limit : "0", // Event Handler Settings (all my handlers are in the Handler.js file)file_dialog_start_handler : fileDialogStart,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, // Button Settingsbutton_image_url : "js/XPButtonUploadText_61x22.png",  <-- 按钮图片路径button_text:    ,    <--   也可以用文字表示,可以用CSS增加样式button_placeholder_id : "spanButtonPlaceholder1",   <--  取代成按钮的元素IDbutton_width: 61,    <---  宽button_height: 22,  <---  高 // Flash Settingsflash_url : "js/swfupload/swfupload.swf",  custom_settings : {progressTarget : "fsUploadProgress1",cancelButtonId : "btnCancel1"}, // Debug Settingsdebug: false  <--  Debug模式开启与关闭});     }</script></head> <body><div id="content"><h2>多档上传</h2><form id="form1" action="index.php" method="post" enctype="multipart/form-data"><p></p><table><tr valign="top"><td><div><div style="padding-left: 5px;"><span id="spanButtonPlaceholder1"></span><input id="btnCancel1" type="button" value="Cancel Uploads" onclick="cancelQueue(upload1);" disabled="disabled" style="margin-left: 2px; height: 22px; font-size: 8pt;" /><br /></div><div class="fieldset flash" id="fsUploadProgress1"> <span class="legend">文件上传进度</span></div></div></td> </tr> </table>  </form></div></body></html>

    upload.php

    <?php //设置sessionif (isset($_POST["PHPSESSID"])) { session_id($_POST["PHPSESSID"]); } session_start();   //做个简易的错误判断,显示于Debug中 if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) { echo "上传时出现错误 - 无法取得文件名。"; }  //FILES参数 $img = $_FILES["Filedata"]["tmp_name"]; $imgname = substr(md5(time().$_FILES["Filedata"]["name"]),0,16).$_FILES["Filedata"]["name"]; $path = './images/'.$imgname; //www.it165.net if(@move_uploaded_file($img, $path)) echo '<a href="http://'.$_SERVER['HTTP_HOST'].'/weine/images/'.$imgname.'" target="_blank">'.$_FILES['Filedata']['name'].'</a><BR>上传成功!'; else echo '图片上传发生错误。'; ?>        

    郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表