当前位置:网站首页>Uploads labs range (with source code analysis) (under update)
Uploads labs range (with source code analysis) (under update)
2022-07-03 15:59:00 【Mung east corner】
pass-01
There is front-end validation
onsubmit: When submitting Forms Execute a paragraph when JavaScript. It only recognizes true perhaps false. If you don't return a value , The default is true
Write a picture of horse , The suffix is the picture suffix , then bp Just grab the bag and change it
Ant sword connection
Source code analysis
front end :
checkile() function
function checkFile() {
var file = document.getElementsByName('upload_file')[0].value;
if (file == null || file == "") {
alert(" Please select the file to upload !");
return false;
}
// Define the types of files allowed to be uploaded
var allow_ext = ".jpg|.png|.gif";
// Extract the type of uploaded file
var ext_name = file.substring(file.lastIndexOf("."));
// Determine whether the type of uploaded file is allowed to be uploaded
if (allow_ext.indexOf(ext_name + "|") == -1) {
var errMsg = " The file is not allowed to upload , Please upload " + allow_ext + " Files of type , The current file type is :" + ext_name;
alert(errMsg);
return false;
}
}
First, through getElementsByName Get form elements , It also gets an array of classes , If you want to get an element accurately , You can use array subscripts to get , So here document.getElementsByName('upload_file')[0].value; You get the file name .
Back if Statement to determine whether the uploaded file is empty
substring() Method is used to extract characters that are mediated between two specified subscripts .
example :
var str="Hello world!";
document.write(str.substring(3)+"<br>");
document.write(str.substring(3,7));
---------------------------------------------------------------------
lo world!
lo w
indexOf() Method to return the first occurrence of a specified string value in the string . lastIndexOf() Method to get the suffix Returns the last position of the specified value in the string that calls the method , If not, return -1. Look forward from the back of the string , from fromIndex Start at . The characters in the string are indexed from left to right . Index of the first character (index) yes 0, The index of the last character is stringName.length - 1. Example :
String name = "upload.doc";
// Get suffix
String sname = name.substring(name.lastIndexOf("."));
// get upload part
String fileName=name.substring(0,name.lastIndexOf("."));
if (allow_ext.indexOf(ext_name + "|") == -1) , Find the suffix just extracted in the suffix that allows uploading , If you can't find it indexOf() Function will return -1, In this way, we can judge
边栏推荐
- A Fei's expectation
- 请求头不同国家和语言的表示
- [combinatorial mathematics] binomial theorem and combinatorial identity (binomial theorem | three combinatorial identities | recursive formula 1 | recursive formula 2 | recursive formula 3 Pascal / Ya
- 《微服务设计》读书笔记(下)
- 互斥对象与临界区的区别
- Get the executable path through the process PID (queryfullprocessimagename)
- Microservices Seata distributed transactions
- Three dimensional reconstruction of deep learning
- 请做好3年内随时失业的准备?
- WinDbg分析dump文件
猜你喜欢
Find mapping relationship
Popular understanding of random forest
工资3000,靠“视频剪辑”月入40000:会赚钱的人,从不靠拼命!
Principles of several common IO models
C language brush questions ~leetcode and simple questions of niuke.com
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)
使用AUR下载并安装常用程序
“用Android复刻Apple产品UI”(2)——丝滑的AppStore卡片转场动画
找映射关系
Function introduction of JMeter thread group
随机推荐
Detailed explanation of string function and string function with unlimited length
First!! Is lancet hungry? Official documents
Create gradle project
嵌入式开发:避免开源软件的7个理由
nifi从入门到实战(保姆级教程)——flow
软件逆向破解入门系列(1)—xdbg32/64的常见配置及功能窗口
Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
MB10M-ASEMI整流桥MB10M
VS2017通过IP调试驱动(双机调试)
请求头不同国家和语言的表示
Popular understanding of linear regression (II)
Principles of several common IO models
Microservice API gateway zuul
C language brush questions ~leetcode and simple questions of niuke.com
Unityshader - materialcapture material capture effect (Emerald axe)
Project -- high concurrency memory pool
Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
阿飞的期望
Why can't strings be directly compared with equals; Why can't some integers be directly compared with the equal sign
软件安装信息、系统服务在注册表中的位置