微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ajax 上传文件的例子

1.

下载upload ajax文件,我这里是直接下载好了了

<script>
//ajax  upload file
;(function(e){"use strict";function t(t){var r=t.data;t.isDefaultPrevented()||(t.preventDefault(),e(t.target).ajaxSubmit(r))}function r(t){var r=t.target,a=e(r);if(!a.is("[type=submit],[type=image]")){var n=a.closest("[type=submit]");if(0===n.length)return;r=n[0]}var i=this;if(i.clk=r,"image"==r.type)if(void 0!==t.offsetX)i.clk_x=t.offsetX,i.clk_y=t.offsetY;else if("function"==typeof e.fn.offset){var o=a.offset();i.clk_x=t.pageX-o.left,i.clk_y=t.pageY-o.top}else i.clk_x=t.pageX-r.offsetLeft,i.clk_y=t.pageY-r.offsetTop;setTimeout(function(){i.clk=i.clk_x=i.clk_y=null},100)}function a(){if(e.fn.ajaxSubmit.debug){var t="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(t):window.opera&&window.opera.postError&&window.opera.postError(t)}}var n={};n.fileapi=void 0!==e("<input type='file'/>").get(0).files,n.formdata=void 0!==window.FormData;var i=!!e.fn.prop;e.fn.attr2=function(){if(!i)return this.attr.apply(this,arguments);var e=this.prop.apply(this,arguments);return e&&e.jquery||"string"==typeof e?e:this.attr.apply(this,arguments)},e.fn.ajaxSubmit=function(t){function r(r){var a,n,i=e.param(r,t.Traditional).split("&"),o=i.length,s=[];for(a=0;o>a;a++)i[a]=i[a].replace(/\+/g," "),n=i[a].split("="),s.push([decodeURIComponent(n[0]),decodeURIComponent(n[1])]);return s}function o(a){for(var n=new FormData,i=0;a.length>i;i++)n.append(a[i].name,a[i].value);if(t.exTradata){var o=r(t.exTradata);for(i=0;o.length>i;i++)o[i]&&n.append(o[i][0],o[i][1])}t.data=null;var s=e.extend(!0,{},e.ajaxSettings,t,{contentType:!1,processData:!1,cache:!1,type:u||"POST"});t.uploadProgress&&(s.xhr=function(){var r=e.ajaxSettings.xhr();return r.upload&&r.upload.addEventListener("progress",function(e){var r=0,a=e.loaded||e.position,n=e.total;e.lengthComputable&&(r=Math.ceil(100*(a/n))),t.uploadProgress(e,a,r)},!1),r}),s.data=null;var l=s.beforeSend;return s.beforeSend=function(e,r){r.data=t.formData?t.formData:n,l&&l.call(this,e,e.ajax(s)}function s(r){function n(e){var t=null;try{e.contentwindow&&(t=e.contentwindow.document)}catch(r){a("cannot get iframe.contentwindow document: "+r)}if(t)return t;try{t=e.contentDocument?e.contentDocument:e.document}catch(r){a("cannot get iframe.contentDocument: "+r),t=e.document}return t}function o(){function t(){try{var e=n(g).readyState;a("state = "+e),e&&"uninitialized"==e.toLowerCase()&&setTimeout(t,50)}catch(r){a("Server abort: ",r," (",r.name,")"),s(k),j&&clearTimeout(j),j=void 0}}var r=f.attr2("target"),i=f.attr2("action");w.setAttribute("target",d),(!u||/post/i.test(u))&&w.setAttribute("method","POST"),i!=m.url&&w.setAttribute("action",m.url),m.skipEncodingOverride||u&&!/post/i.test(u)||f.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),m.timeout&&(j=setTimeout(function(){T=!0,s(D)},m.timeout));var o=[];try{if(m.exTradata)for(var l in m.exTradata)m.exTradata.hasOwnProperty(l)&&(e.isPlainObject(m.exTradata[l])&&m.exTradata[l].hasOwnProperty("name")&&m.exTradata[l].hasOwnProperty("value")?o.push(e('<input type="hidden" name="'+m.exTradata[l].name+'">').val(m.exTradata[l].value).appendTo(w)[0]):o.push(e('<input type="hidden" name="'+l+'">').val(m.exTradata[l]).appendTo(w)[0]));m.ifraMetarget||v.appendTo("body"),g.attachEvent?g.attachEvent("onload",s):g.addEventListener("load",s,setTimeout(t,15);try{w.submit()}catch(c){var p=document.createElement("form").submit;p.apply(w)}}finally{w.setAttribute("action",i),r?w.setAttribute("target",r):f.removeAttr("target"),e(o).remove()}}function s(t){if(!x.aborted&&!F){if(M=n(g),M||(a("cannot access response document"),t=k),t===D&&x)return x.abort("timeout"),S.reject(x,"timeout"),void 0;if(t==k&&x)return x.abort("server abort"),"error","server abort"),void 0;if(M&&M.location.href!=m.iframeSrc||T){g.detachEvent?g.detachEvent("onload",s):g.removeEventListener("load",!1);var r,i="success";try{if(T)throw"timeout";var o="xml"==m.dataType||M.XMLDocument||e.isXMLDoc(M);if(a("isXml="+o),!o&&window.opera&&(null===M.body||!M.body.innerHTML)&&--O)return a("requeing onLoad callback,DOM not available"),setTimeout(s,250),void 0;var u=M.body?M.body:M.documentElement;x.responseText=u?u.innerHTML:null,x.responseXML=M.XMLDocument?M.XMLDocument:M,o&&(m.dataType="xml"),x.getResponseHeader=function(e){var t={"content-type":m.dataType};return t[e.toLowerCase()]},u&&(x.status=Number(u.getAttribute("status"))||x.status,x.statusText=u.getAttribute("statusText")||x.statusText);var l=(m.dataType||"").toLowerCase(),c=/(json|script|text)/.test(l);if(c||m.textarea){var f=M.getElementsByTagName("textarea")[0];if(f)x.responseText=f.value,x.status=Number(f.getAttribute("status"))||x.status,x.statusText=f.getAttribute("statusText")||x.statusText;else if(c){var d=M.getElementsByTagName("pre")[0],h=M.getElementsByTagName("body")[0];d?x.responseText=d.textContent?d.textContent:d.innerText:h&&(x.responseText=h.textContent?h.textContent:h.innerText)}}else"xml"==l&&!x.responseXML&&x.responseText&&(x.responseXML=X(x.responseText));try{E=_(x,l,m)}catch(b){i="parsererror",x.error=r=b||i}}catch(b){a("error caught: ",b),i="error",x.error=r=b||i}x.aborted&&(a("upload aborted"),i=null),x.status&&(i=x.status>=200&&300>x.status||304===x.status?"success":"error"),"success"===i?(m.success&&m.success.call(m.context,E,"success",x),S.resolve(x.responseText,p&&e.event.trigger("ajaxSuccess",[x,m])):i&&(void 0===r&&(r=x.statusText),m.error&&m.error.call(m.context,x,i,r),p&&e.event.trigger("ajaxError",m,r])),p&&e.event.trigger("ajaxComplete",m]),p&&!--e.active&&e.event.trigger("ajaxStop"),m.complete&&m.complete.call(m.context,F=!0,m.timeout&&clearTimeout(j),setTimeout(function(){m.ifraMetarget?v.attr("src",m.iframeSrc):v.remove(),x.responseXML=null},100)}}}var l,c,p,d,v,g,b,y,T,j,w=f[0],S=e.Deferred();if(S.abort=function(e){x.abort(e)},r)for(c=0;h.length>c;c++)l=e(h[c]),i?l.prop("disabled",!1):l.removeAttr("disabled");if(m=e.extend(!0,t),m.context=m.context||m,d="jqFormIO"+(new Date).getTime(),m.ifraMetarget?(v=e(m.ifraMetarget),y=v.attr2("name"),y?d=y:v.attr2("name",d)):(v=e('<iframe name="'+d+'" src="'+m.iframeSrc+'" />'),v.css({position:"absolute",top:"-1000px",left:"-1000px"})),g=v[0],x={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(t){var r="timeout"===t?"timeout":"aborted";a("aborting upload... "+r),this.aborted=1;try{g.contentwindow.document.execCommand&&g.contentwindow.document.execCommand("Stop")}catch(n){}v.attr("src",m.iframeSrc),x.error=r,r]),r)}},p=m.global,p&&0===e.active++&&e.event.trigger("ajaxStart"),p&&e.event.trigger("ajaxSend",m.beforeSend&&m.beforeSend.call(m.context,m)===!1)return m.global&&e.active--,S.reject(),S;if(x.aborted)return S.reject(),S;b=w.clk,b&&(y=b.name,y&&!b.disabled&&(m.exTradata=m.exTradata||{},m.exTradata[y]=b.value,"image"==b.type&&(m.exTradata[y+".x"]=w.clk_x,m.exTradata[y+".y"]=w.clk_y)));var D=1,k=2,A=e("Meta[name=csrf-token]").attr("content"),L=e("Meta[name=csrf-param]").attr("content");L&&A&&(m.exTradata=m.exTradata||{},m.exTradata[L]=A),m.forceSync?o():setTimeout(o,10);var E,M,F,O=50,X=e.parseXML||function(e,t){return window.ActiveXObject?(t=new ActiveXObject("Microsoft.XMLDOM"),t.async="false",t.loadXML(e)):t=(new DOMParser).parseFromString(e,"text/xml"),t&&t.documentElement&&"parsererror"!=t.documentElement.nodeName?t:null},C=e.parseJSON||function(e){return window.eval("("+e+")")},_=function(t,a){var n=t.getResponseHeader("content-type")||"",i="xml"===r||!r&&n.indexOf("xml")>=0,o=i?t.responseXML:t.responseText;return i&&"parsererror"===o.documentElement.nodeName&&e.error&&e.error("parsererror"),a&&a.dataFilter&&(o=a.dataFilter(o,r)),"string"==typeof o&&("json"===r||!r&&n.indexOf("json")>=0?o=C(o):("script"===r||!r&&n.indexOf("javascript")>=0)&&e.globalEval(o)),o};return S}if(!this.length)return a("ajaxSubmit: skipping submit process - no element selected"),this;var u,f=this;"function"==typeof t?t={success:t}:void 0===t&&(t={}),u=t.type||this.attr2("method"),l=t.url||this.attr2("action"),c="string"==typeof l?e.trim(l):"",c=c||window.location.href||"",c&&(c=(c.match(/^([^#]+)/)||[])[1]),t=e.extend(!0,{url:c,success:e.ajaxSettings.success,type:u||e.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},t);var m={};if(this.trigger("form-pre-serialize",[this,m.veto)return a("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(t.beforeSerialize&&t.beforeSerialize(this,t)===!1)return a("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var p=t.Traditional;void 0===p&&(p=e.ajaxSettings.Traditional);var d,h=[],v=this.formToArray(t.semantic,h);if(t.data&&(t.exTradata=t.data,d=e.param(t.data,p)),t.beforeSubmit&&t.beforeSubmit(v,this,t)===!1)return a("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[v,m.veto)return a("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var g=e.param(v,p);d&&(g=g?g+"&"+d:d),"GET"==t.type.toupperCase()?(t.url+=(t.url.indexOf("?")>=0?"&":"?")+g,t.data=null):t.data=g;var x=[];if(t.resetForm&&x.push(function(){f.resetForm()}),t.clearForm&&x.push(function(){f.clearForm(t.includeHidden)}),!t.dataType&&t.target){var b=t.success||function(){};x.push(function(r){var a=t.replaceTarget?"replaceWith":"html";e(t.target)[a](r).each(b,arguments)})}else t.success&&x.push(t.success);if(t.success=function(e,a){for(var n=t.context||this,i=0,o=x.length;o>i;i++)x[i].apply(n,[e,a||f,f])},t.error){var y=t.error;t.error=function(e,a){var n=t.context||this;y.apply(n,f])}}if(t.complete){var T=t.complete;t.complete=function(e,r){var a=t.context||this;T.apply(a,f])}}var j=e("input[type=file]:enabled",this).filter(function(){return""!==e(this).val()}),w=j.length>0,S="multipart/form-data",D=f.attr("enctype")==S||f.attr("encoding")==S,k=n.fileapi&&n.formdata;a("fileAPI :"+k);var A,L=(w||D)&&!k;t.iframe!==!1&&(t.iframe||L)?t.closeKeepAlive?e.get(t.closeKeepAlive,function(){A=s(v)}):A=s(v):A=(w||D)&&k?o(v):e.ajax(t),f.removeData("jqxhr").data("jqxhr",A);for(var E=0;h.length>E;E++)h[E]=null;return this.trigger("form-submit-notify",t]),this},e.fn.ajaxForm=function(n){if(n=n||{},n.delegation=n.delegation&&e.isFunction(e.fn.on),!n.delegation&&0===this.length){var i={s:this.selector,c:this.context};return!e.isReady&&i.s?(a("DOM not ready,queuing ajaxForm"),e(function(){e(i.s,i.c).ajaxForm(n)}),this):(a("terminating; zero elements found by selector"+(e.isReady?"":" (DOM not ready)")),this)}return n.delegation?(e(document).off("submit.form-plugin",this.selector,t).off("click.form-plugin",r).on("submit.form-plugin",t).on("click.form-plugin",this):this.ajaxFormUnbind().bind("submit.form-plugin",t).bind("click.form-plugin",e.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")},e.fn.formToArray=function(t,r){var a=[];if(0===this.length)return a;var i=this[0],o=t?i.getElementsByTagName("*"):i.elements;if(!o)return a;var s,u,f,p;for(s=0,m=o.length;m>s;s++)if(f=o[s],l=f.name,l&&!f.disabled)if(t&&i.clk&&"image"==f.type)i.clk==f&&(a.push({name:l,value:e(f).val(),type:f.type}),a.push({name:l+".x",value:i.clk_x},{name:l+".y",value:i.clk_y}));else if(c=e.fieldValue(f,!0),c&&c.constructor==Array)for(r&&r.push(f),u=0,p=c.length;p>u;u++)a.push({name:l,value:c[u]});else if(n.fileapi&&"file"==f.type){r&&r.push(f);var d=f.files;if(d.length)for(u=0;d.length>u;u++)a.push({name:l,value:d[u],type:f.type});else a.push({name:l,value:"",type:f.type})}else null!==c&&c!==void 0&&(r&&r.push(f),a.push({name:l,value:c,type:f.type,required:f.required}));if(!t&&i.clk){var h=e(i.clk),v=h[0];l=v.name,l&&!v.disabled&&"image"==v.type&&(a.push({name:l,value:h.val()}),value:i.clk_y}))}return a},e.fn.formSerialize=function(t){return e.param(this.formToArray(t))},e.fn.fieldSerialize=function(t){var r=[];return this.each(function(){var a=this.name;if(a){var n=e.fieldValue(this,t);if(n&&n.constructor==Array)for(var i=0,o=n.length;o>i;i++)r.push({name:a,value:n[i]});else null!==n&&n!==void 0&&r.push({name:this.name,value:n})}}),e.param(r)},e.fn.fieldValue=function(t){for(var r=[],a=0,n=this.length;n>a;a++){var i=this[a],o=e.fieldValue(i,t);null===o||void 0===o||o.constructor==Array&&!o.length||(o.constructor==Array?e.merge(r,o):r.push(o))}return r},e.fieldValue=function(t,r){var a=t.name,n=t.type,i=t.tagName.toLowerCase();if(void 0===r&&(r=!0),r&&(!a||t.disabled||"reset"==n||"button"==n||("checkBox"==n||"radio"==n)&&!t.checked||("submit"==n||"image"==n)&&t.form&&t.form.clk!=t||"select"==i&&-1==t.selectedindex))return null;if("select"==i){var o=t.selectedindex;if(0>o)return null;for(var s=[],u=t.options,l="select-one"==n,c=l?o+1:u.length,f=l?o:0;c>f;f++){var m=u[f];if(m.selected){var p=m.value;if(p||(p=m.attributes&&m.attributes.value&&!m.attributes.value.specified?m.text:m.value),l)return p;s.push(p)}}return s}return e(t).val()},e.fn.clearForm=function(t){return this.each(function(){e("input,select,textarea",this).clearFields(t)})},e.fn.clearFields=e.fn.clearInputs=function(t){var r=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i;return this.each(function(){var a=this.type,n=this.tagName.toLowerCase();r.test(a)||"textarea"==n?this.value="":"checkBox"==a||"radio"==a?this.checked=!1:"select"==n?this.selectedindex=-1:"file"==a?/MSIE/.test(navigator.userAgent)?e(this).replaceWith(e(this).clone(!0)):e(this).val(""):t&&(t===!0&&/hidden/.test(a)||"string"==typeof t&&e(this).is(t))&&(this.value="")})},e.fn.resetForm=function(){return this.each(function(){("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})},e.fn.enable=function(e){return void 0===e&&(e=!0),this.each(function(){this.disabled=!e})},e.fn.selected=function(t){return void 0===t&&(t=!0),this.each(function(){var r=this.type;if("checkBox"==r||"radio"==r)this.checked=t;else if("option"==this.tagName.toLowerCase()){var a=e(this).parent("select");t&&a[0]&&"select-one"==a[0].type&&a.find("option").selected(!1),this.selected=t}})},e.fn.ajaxSubmit.debug=!1})("undefined"!=typeof jQuery?jQuery:window.Zepto);
</script>

2

加载jquery

3

js文件盒css文件

<script>
(function() {
    
var bar1 = $('.bar1');
var percent1 = $('.percent1');
var status1 = $('#status1');

var bar2 = $('.bar2');
var percent2 = $('.percent2');
var status2 = $('#status2');

var bar3 = $('.bar3');
var percent3 = $('.percent3');
var status3 = $('#status3');




jQuery('#uploadform').ajaxForm({
    beforeSend: function() {
    	myfile1 = jQuery(".myfile1").val();
    	myfile2 = jQuery(".myfile2").val();
    	myfile3 = jQuery(".myfile3").val();
	   if(myfile1!=""){     
	        status1.empty();
	        var percentVal1 = '0%';
	        bar1.width(percentVal1)
	        percent1.html(percentVal1);
	   }
	   if(myfile2!=""){    
	        status2.empty();
	        var percentVal2 = '0%';
	        bar2.width(percentVal2)
	        percent2.html(percentVal2);
	   }
	   if(myfile3!=""){
	        status3.empty();
	        var percentVal3 = '0%';
	        bar3.width(percentVal3)
	        percent3.html(percentVal3);
	   }
    },uploadProgress: function(event,position,total,percentComplete) {
    	myfile1 = jQuery(".myfile1").val();
    	myfile2 = jQuery(".myfile2").val();
    	myfile3 = jQuery(".myfile3").val();
	   if(myfile1!=""){  
	        var percentVal1 = percentComplete + '%';
	        bar1.width(percentVal1)
	        percent1.html(percentVal1);
	   }
	   if(myfile2!=""){
	        var percentVal2 = percentComplete + '%';
	        bar2.width(percentVal2)
	        percent2.html(percentVal2);
	   }
	   if(myfile3!=""){
	        var percentVal3 = percentComplete + '%';
	        bar3.width(percentVal3)
	        percent3.html(percentVal3);
	   }
    },success: function() {
    	myfile1 = jQuery(".myfile1").val();
    	myfile2 = jQuery(".myfile2").val();
    	myfile3 = jQuery(".myfile3").val();
	   if(myfile1!=""){
	        var percentVal1 = '100%';
	        bar1.width(percentVal1)
	        percent1.html(percentVal1);
	   }
	   if(myfile2!=""){
	        var percentVal2 = '100%';
	        bar2.width(percentVal2)
	        percent2.html(percentVal2);
	   }
	   if(myfile3!=""){
	        var percentVal3 = '100%';
	        bar3.width(percentVal3)
	        percent3.html(percentVal3);
	   }
    },complete: function(xhr) {
		myfile1 = jQuery(".myfile1").val();
		myfile2 = jQuery(".myfile2").val();
		myfile3 = jQuery(".myfile3").val();
	   	if(xhr.responseText == "too-big"){
			alert("upload file is to big!less than <?PHP echo Mage::getStoreConfig("email/attachment/filesize"); ?> KB");
		}else{
			jQuery(".attachment").val(xhr.responseText);
		}
	   
	}
}); 

})();  
jQuery(document).ready(function(){
	jQuery(".upload").click(function(){
		myfile1 = jQuery(".myfile1").val();
		myfile2 = jQuery(".myfile2").val();
		myfile3 = jQuery(".myfile3").val();
		if((myfile1=="")&&(myfile1=="")&&(myfile1=="")){
			alert("您必须选择一个文件,方可上传");
		}else{
			jQuery('#uploadform').submit();
		}
	});

	
});
</script>
<style>
.progress1 { position:relative; width:200px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; }
.bar1 { background-color: #B4F5B4; width:0%; height:12px; border-radius: 3px; }
.percent1 { position:absolute; display:inline-block; top:1px; left:48%; }
.progress2 { position:relative; width:200px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; }
.bar2 { background-color: #B4F5B4; width:0%; height:12px; border-radius: 3px; }
.percent2 { position:absolute; display:inline-block; top:1px; left:48%; }
.progress3 { position:relative; width:200px; border: 1px solid #ddd; padding: 1px; border-radius: 3px; }
.bar3 { background-color: #B4F5B4; width:0%; height:12px; border-radius: 3px; }
.percent3 { position:absolute; display:inline-block; top:1px; left:48%; }
.upload_bumit{float:left;}
.upload_input{float:left;}
.thisorder td{color:#cc0000}
.thisordeRSS td{color:#0099FF;}
#uploadform{ background: none repeat scroll 0 0 #F2F2F2;
    margin: 5px 0;
    padding: 5px;
	display:none;
    width: 892px;}
.myfile1{margin:0 0 4px 0}
.myfile2{margin:0 0 4px 0}
.myfile3{margin:0 0 4px 0}
</style>

4上传文件的html部分:
<form id="uploadform" action="<?PHP echo $this->getUrl('developm/xuqiu/upload');?>"" method="post" enctype="multipart/form-data">
			<input type="hidden" name="form_key" value="<?PHP echo Mage::getSingleton('core/session')->getFormKey();?>" /> 
			
					<div class="upload_input">
						<input type="file" name="myfile1" class="myfile1" value="上传附件">
						<div class="progress1">
							   <div class="bar1"></div >
							   <div class="percent1">0%</div >
						</div>
						<div id="status1"></div>
					</div>
					
					<div class="upload_input">
						<input type="file" name="myfile2"  class="myfile2"  value="上传附件">
						<div class="progress2">
							   <div class="bar2"></div >
							   <div class="percent2">0%</div >
						</div>
						<div id="status2"></div>
					</div>
					
					<div class="upload_input">
						<input type="file" name="myfile3"  class="myfile3"  value="上传附件">
						<div class="progress3">
							   <div class="bar3"></div >
							   <div class="percent3">0%</div >
						</div>
						<div id="status3"></div>
					</div>
					<div  class="upload_bumit">				       
						<input class="upload" type="button" value="上传附件">
					</div>
					<div style="clear:both;"></div>
		</form>

5

接收文件PHP文件部分:

public function uploadAction() {
	 	$dd = "";
	 	$zg_size = Mage::getStoreConfig("email/attachment/filesize")*1024;
	 	$f_size_1 = $_FILES["myfile1"]["size"];
	 	$f_size_2 = $_FILES["myfile2"]["size"];
	 	$f_size_3 = $_FILES["myfile3"]["size"];
	 	if(($f_size_1>$zg_size)||($f_size_2>$zg_size)||($f_size_3>$zg_size)){
	 		echo  "too-big";
	 	}else{
		 	if($_FILES["myfile1"]['name']!=""){
		 		 $f_name = $_FILES["myfile1"]["name"];
		 		 $hz = strrev(substr(strrev($f_name),4));
		 		 $datatimes = date('Y-m-d-G-i-s',time());
		 		 $randnumber1 =  rand(1,5000);
		 		 $randnumber2 =  rand(5000,9999);
		 		 $filename1 = $randnumber1."-".$randnumber2."-".$datatimes.$hz;
		 		 $filedir1 = "var/email/send/" . $filename1;
		 		 move_uploaded_file($_FILES["myfile1"]["tmp_name"],$filedir1);
		 		 $dd .= $filedir1."&&";
		 		 
		 		 
		 	}
		 	
		 	if($_FILES["myfile2"]['name']!=""){
		 		 $f_name = $_FILES["myfile2"]["name"];
		 		 $hz = strrev(substr(strrev($f_name),9999);
		 		 $filename2 = $randnumber1."-".$randnumber2."-".$datatimes.$hz;
		 		 $filedir2 = "var/email/send/" . $filename2;
		 		 move_uploaded_file($_FILES["myfile2"]["tmp_name"],$filedir2);
		 		 $dd .= $filedir2."&&";
		 	}
		 	
		 	
		 	if($_FILES["myfile3"]['name']!=""){
		 		 $f_name = $_FILES["myfile3"]["name"];
		 		 $hz = strrev(substr(strrev($f_name),9999);
		 		 $filename3 = $randnumber1."-".$randnumber2."-".$datatimes.$hz;
		 		 $filedir3 = "var/email/send/" . $filename3;
		 		 move_uploaded_file($_FILES["myfile3"]["tmp_name"],$filedir3);
		 		 $dd .= $filedir3."&&";
		 	}
		 	if($dd!=""){
		 		$dd = substr($dd,strlen($dd)-2);
		 	}
		 	echo $dd;
	 	}
     	
	 }



6测试吧。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐