当前位置:网站首页>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
边栏推荐
- 通过进程PID获取可执行文件路径(QueryFullProcessImageName)
- Effect of ARP package on FTP dump under vxworks-6.6 system
- Use percent sign in CString
- App mobile terminal test [3] ADB command
- 利用MySQL中的乐观锁和悲观锁实现分布式锁
- Detailed explanation of four modes of distributed transaction (Seata)
- pycharm错Error updating package list: connect timed out
- 【OpenCV 例程200篇】217. 鼠标交互获取多边形区域(ROI)
- Calibre LVL
- Redis高可用与持久化
猜你喜欢

Microservice - Nacos registration center and configuration center

CString getbuffer and releasebuffer instructions

Microservice - fuse hystrix

App移动端测试【5】文件的写入、读取

Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14

VS2017通过IP调试驱动(双机调试)

MB10M-ASEMI整流桥MB10M

ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装

The difference between calling by value and simulating calling by reference
![App mobile terminal test [3] ADB command](/img/f1/4bff6e66b77d0f867bf7237019e982.png)
App mobile terminal test [3] ADB command
随机推荐
Microservice - Nacos registration center and configuration center
秒杀系统3-商品列表和商品详情
Break through 1million, sword finger 2million!
Project -- high concurrency memory pool
Why can't strings be directly compared with equals; Why can't some integers be directly compared with the equal sign
Semi supervised learning
Go语言自学系列 | golang中的if else语句
半监督学习
【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
[combinatorics] combinatorial identities (recursive combinatorial identities | sum of variable terms | simple combinatorial identities and | sum of variable terms | staggered sums of combinatorial ide
[combinatorial mathematics] binomial theorem and combinatorial identity (binomial theorem | three combinatorial identities | recursive formula 1 | recursive formula 2 | recursive formula 3 Pascal / Ya
A Fei's expectation
pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
pycharm错Error updating package list: connect timed out
首发!!lancet饿了么官方文档
秒殺系統3-商品列錶和商品詳情
Unity function - unity offline document download and use
Embedded development: seven reasons to avoid open source software
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) -3 Image control