当前位置:网站首页>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
边栏推荐
- Pandora IOT development board learning (HAL Library) - Experiment 5 external interrupt experiment (learning notes)
- VS2017通过IP调试驱动(双机调试)
- 嵌入式开发:避免开源软件的7个理由
- Break through 1million, sword finger 2million!
- Popular understanding of ovo and ovr
- 驱动与应用程序通信
- nifi从入门到实战(保姆级教程)——flow
- Jmeter线程组功能介绍
- The difference between calling by value and simulating calling by reference
- 秒杀系统3-商品列表和商品详情
猜你喜欢
[redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)
Srs4.0+obs studio+vlc3 (environment construction and basic use demonstration)
Microservice API gateway
Seckill system 3- product list and product details
子类隐藏父类的同名函数
Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
App mobile terminal test [3] ADB command
几种常见IO模型的原理
[list to map] collectors Tomap syntax sharing (case practice)
Principles of several common IO models
随机推荐
App mobile terminal test [5] file writing and reading
驱动与应用程序通信
"Remake Apple product UI with Android" (3) - elegant statistical chart
Function introduction of JMeter thread group
坚持输出需要不断学习
首发!!lancet饿了么官方文档
Detailed pointer advanced 1
Microservice - fuse hystrix
2022年Q2加密市场投融资报告:GameFi成为投资关键词
Problems of CString in multithreading
Redis高可用与持久化
Location of software installation information and system services in the registry
[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree
Why can't strings be directly compared with equals; Why can't some integers be directly compared with the equal sign
Under VC, Unicode and ANSI are converted to each other, cstringw and std:: string are converted to each other
How to use AAB to APK and APK to AAB of Google play apps on the shelves
Visual upper system design and development (Halcon WinForm) -4 Communication management
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
Pandora IOT development board learning (HAL Library) - Experiment 5 external interrupt experiment (learning notes)
秒杀系统1-登录功能