首頁 php教程 PHP源码 swfupload 批量上传源码

swfupload 批量上传源码

May 25, 2016 pm 05:13 PM

                       

                       

1. [代码][PHP]代码    

//首先  准备 swfupload 包
//前端用户体验页面
<!DOCTYPE html>
<html>
<head>
<title>SWFUpload Demos - Application Demo</title>
<link href="./default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./swfupload/swfupload.js"></script>
<script type="text/javascript" src="./swfupload/jquery-1.4.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>
<script type="text/javascript">
$(function(){
$(&#39;#btn&#39;).bind(&#39;click&#39;,path);

});

function path()
{
 var url=&#39;&#39;;
$(&#39;#thumbnails img&#39;).each(function(){
url=$(this).attr(&#39;id&#39;)+&#39;{#@T@#}&#39;+url;
})
 alert(url);
}

  var swfu;
  window.onload = function () {
   swfu = new SWFUpload({
    // Backend Settings
    upload_url: "upload.php",
    post_params: {"PHPSESSID": "<?php echo session_id(); ?>"},

    // File Upload Settings
    file_size_limit : "800", // 2MB 最大容量限制
    file_types : "*.jpg",
    file_types_description : "JPG Images",
    file_upload_limit : 5,//上传数量限制

    // Event Handler Settings - these functions as defined in Handlers.js
    //  The handlers are not part of SWFUpload but are part of my website and control how
    //  my website reacts to the SWFUpload events.
    swfupload_preload_handler : preLoad,
    swfupload_load_failed_handler : loadFailed,
    file_queue_error_handler : fileQueueError,
    file_dialog_complete_handler : fileDialogComplete,
    upload_progress_handler : uploadProgress,
    upload_error_handler : uploadError,
    upload_success_handler : uploadSuccess,
    upload_complete_handler : uploadComplete,

    // Button Settings
    button_image_url : "images/SmallSpyGlassWithTransperancy_17x18.png",
    button_placeholder_id : "spanButtonPlaceholder",
    button_width: 200,
    button_height: 18,
    button_text : &#39;<span class="button">Select Images <span class="buttonSmall">(800 k Max)[*.jpeg]</span></span>&#39;,
    button_text_style : &#39;.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }&#39;,
    button_text_top_padding: 0,
    button_text_left_padding: 18,
    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
    button_cursor: SWFUpload.CURSOR.HAND,
    
    // Flash Settings
    flash_url : "./swfupload/swfupload.swf",
    flash9_url : "./swfupload/swfupload_FP9.swf",

    custom_settings : {
     upload_target : "pFileProgressContainer"
    },
    
    // Debug Settings
    debug: false
   });
  };
 </script>
</head>
<body>
<h2>最多上传5张图片<h2>
 <form>
  <p style="width: 200px; height: 18px; border: solid 1px #7FAAFF; background-color: #C5D9FF; padding: 2px;">
   <span id="spanButtonPlaceholder"></span>
  </p>
 </form>
 <p id="pFileProgressContainer" style="height: 75px;"></p>
 <p id="thumbnails" style=&#39;width:500px;border:1px solid lime;padding-left:20px&#39;></p>
</p>
<button id=&#39;btn&#39;>提交</button>
</body>
</html>

//后台处理页面 upload.php
<?php
  
 if (isset($_POST["PHPSESSID"])) {
  session_id($_POST["PHPSESSID"]);
 }

 session_start();
 ini_set("html_errors", "0");

 // Check the upload
 if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
  echo "ERROR:invalid upload";
  exit(0);
 }

 // Get the image and create a thumbnail
 $img = imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]);
 if (!$img) {
  echo "ERROR:could not create image handle ". $_FILES["Filedata"]["tmp_name"];
  exit(0);
 }

 $width = imageSX($img);
 $height = imageSY($img);

 if (!$width || !$height) {
  echo "ERROR:Invalid width or height";
  exit(0);
 }

 // Build the thumbnail
 $target_width = 100;
 $target_height = 100;
 $target_ratio = $target_width / $target_height;

 $img_ratio = $width / $height;

 if ($target_ratio > $img_ratio) {
  $new_height = $target_height;
  $new_width = $img_ratio * $target_height;
 } else {
  $new_height = $target_width / $img_ratio;
  $new_width = $target_width;
 }

 if ($new_height > $target_height) {
  $new_height = $target_height;
 }
 if ($new_width > $target_width) {
  $new_height = $target_width;
 }

 $new_img = ImageCreateTrueColor(100, 100);
 if (!@imagefilledrectangle($new_img, 0, 0, $target_width-1, $target_height-1, 0)) { // Fill the image black
  echo "ERROR:Could not fill new image";
  exit(0);
 }

 if (!@imagecopyresampled($new_img, $img, ($target_width-$new_width)/2, ($target_height-$new_height)/2, 0, 0, $new_width, $new_height, $width, $height)) {
  echo "ERROR:Could not resize image";
  exit(0);
 }

 if (!isset($_SESSION["file_info"])) {
  $_SESSION["file_info"] = array();
 }

 // Use a output buffering to load the image into a variable
 ob_start();
 imagejpeg($new_img);
 $imagevariable = ob_get_contents();
 ob_end_clean();
 $file_id = md5($_FILES["Filedata"]["tmp_name"] + rand()*100000);
 $_SESSION["file_info"][$file_id] = $imagevariable;
 //上传图片处理

if(!is_dir("uploadimage"))
{
   mkdir("uploadimage");
}
$pre_fix=md5(&#39;120ask120&#39;);
  move_uploaded_file($_FILES["Filedata"]["tmp_name"],trim("./uploadimage/".$pre_fix.$file_id.".jpg"));
/*图片处理结束*/  
 echo "FILEID:" . $file_id; // Return the file id to the script
 
?>
登入後複製

                   

                   

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)