程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHP多圖片上傳實例demo,

PHP多圖片上傳實例demo,

編輯:關於PHP編程

PHP多圖片上傳實例demo,


upload.html

 

<!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" />
<script type="text/javascript" src="http://c.mfniu.com/js/lib/jquery.js"></script>
<title>多圖片上傳實例1</title>
</head>

<body>
<div class="upload_btn" onclick="fileElem.click()">選擇上傳圖片</div>
<form action="upload.php" method="post" enctype="multipart/form-data">
<div id="filebox">
<input class="inputimg" type="file" id="fileElem0" name="img[]" multiple="multiple" accept="image/*" onchange="handleFiles(this)">
</div>
<div class="showimgdiv" id="fileList" ></div>
<br><input class="inputimg" type="submit" value="提交">
</form>
<script>
window.URL = window.URL || window.webkitURL;
var fileList = document.getElementById("fileList");
var num = 0;

function handleFiles(obj) {
var sname = 'fileElem'+num;
num++;
var xname ='fileElem'+num;

$('#'+sname).hide();
$('#filebox').append('<input class="inputimg" type="file" id="'+xname+'" name="img[]" multiple="multiple" accept="image/*" onchange="handleFiles(this)">');

if(fileList.childNodes.length>=6){
alert("最多只能上傳6張圖片哦!");
return false;
}

/* 方法2
if(num>5){
alert("最多只能上傳6張圖片哦!");
return false;
}
*/

var files = obj.files,
img = new Image();

var div = document.createElement("div");//創建一個DIV
div.style.width = "100px";
div.style.height = "100px";
div.style.border = "1px solid #111";
div.style.margin = "2px";
div.style.float = "left";
div.style.boxShadow = " 2px 2px 4px #aaa";


img.src = window.URL.createObjectURL(files[0]);
img.style.width = "100px";
img.style.height = "100px";
img.name="img[]";
img.onload = function(e) {
window.URL.revokeObjectURL(this.src);
}

div.appendChild(img);
fileList.appendChild(div);
}
</script>
</body>
</html>

 

 

 

upload.php

 

<?php

var_dump($_FILES);

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved