jsはアップロードファイルタイプを検証して、jsはローカルファイルを操作します.


jsのいくつかの基本的な応用、時間は長くなって忘れやすいです.まずこれを覚えてください
 

 function lastname(){
		 //          
		var filepath = document.getElementById("img").value; 
		//            ,         
		var re = /(\\+)/g; 
		var filename=filepath.replace(re,"#");
		//            
		var one=filename.split("#");
		//         ,    
		var two=one[one.length-1];
		//         ,      
		var three=two.split(".");
		 //            ,     
		var last=three[three.length-1];
		//            
		var tp ="jpg,gif,bmp,JPG,GIF,BMP,png";
		//                  
		var rs=tp.indexOf(last);
		//            0,             
		if(rs!=-1){
		 return true;
		 }else{ 
		 alert("                 !"); 
		 //$('#subbutton').attr("disabled", "disabled");
		 return false;
	  }
  }
jsはローカルファイルを操作します.これはブラウザのセキュリティ設定を変更してこそ効果があります.前のコードは文字列に対して行うbase 64コードです.

function base64encode(str) {
    var out, i, len;
    var c1, c2, c3;
    len = str.length; 
    i = 0;
    out = "";
    while(i < len) {
	 c1 = str.charCodeAt(i++) & 0xff;
	 if(i == len)
	 {
	     out += base64EncodeChars.charAt(c1 >> 2);
	     out += base64EncodeChars.charAt((c1 & 0x3) << 4);
	     out += "==";
	     break;
	 }
	 c2 = str.charCodeAt(i++);
	 if(i == len)
	 {
	     out += base64EncodeChars.charAt(c1 >> 2);
	     out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
	     out += base64EncodeChars.charAt((c2 & 0xF) << 2);
	     out += "=";
	     break;
	 } 
	 c3 = str.charCodeAt(i++);
	 out += base64EncodeChars.charAt(c1 >> 2);
	 out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
	 out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
	 out += base64EncodeChars.charAt(c3 & 0x3F);
 }
    return out;
}

function getInfo(){
	var declin=';'; 
	var imei;
	var curr_staff_num;
	var update_staff_num;
	var password;
	var ip;  
	var port;  
	var resendTime;
	var dowmloadPage;
	var commandPage;
	var dataTransportPage;  

	imei = document.forms[0].imei.value;   
	curr_staff_num ='<bean:write name="te" property="terminal_no" scope="request"/>';    
	update_staff_num = document.forms[0].terminal_no.value;  
	password =  '<bean:write name="constant" property="constant_password" scope="request"/>';
	ip = '<bean:write name="constant" property="constant_ip" scope="request"/>';
	port = '<bean:write name="constant" property="constant_port" scope="request"/>';  
	resendTime = '<bean:write name="constant" property="constant_connection_time" scope="request"/>';
	dowmloadPage = '<bean:write name="constant" property="constant_down_address" scope="request"/>';
	commandPage = '<bean:write name="constant" property="constant_command_address" scope="request"/>';
	dataTransportPage = '<bean:write name="constant" property="constant_location_address" scope="request"/>';
	
	var str = imei+declin+curr_staff_num+declin+update_staff_num+ 
				declin+password+declin+ip+declin+port
				+declin+resendTime+declin+dowmloadPage+
				declin+commandPage+declin+dataTransportPage+declin;
	return str; 
	//alert(str);  
} 
//       
function saveToTermianl(){  
		var str = getInfo(); 
		//alert(str); 
		var dealStr = base64encode(str);
		//alert(dealStr); 
                 //         
		var fso = new ActiveXObject("Scripting.FileSystemObject");  
		 
		var drives = "c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r"; //,s,t,u,v,w,x,y,z";
		var array = drives.split(","); 
		 
		for(var i =0 ;i<array.length;i++){ 
			var filepath = array[i]+":\\QinYiApp\\Settting\\profile.bin";  
			alert(filepath);     
			if (fso.FileExists(filepath)){      
			   	 //alert("fold exists");     
			    var f1 = fso.CreateTextFile(array[i]+":\\QinYiApp\\Settting\\SettingInfo.txt", true);
			    f1.WriteLine(dealStr);       
			    f1.close(); 
			    alert('         ,               !');
			    document.forms[0].submit(); 
			    return;
			 } 
		}  
		alert('      !                ,       !');
		window.close();
}