当前位置:网站首页>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
边栏推荐
- Redis在Windows以及Linux系统下的安装
- Visual host system design and development (Halcon WinForm)
- How to use AAB to APK and APK to AAB of Google play apps on the shelves
- VC下Unicode和ANSI互转,CStringW和std::string互转
- Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
- Approval process design
- Embedded development: seven reasons to avoid open source software
- Microservices - load balancing ribbon
- 秒杀系统1-登录功能
- June to - -------
猜你喜欢

Popular understanding of random forest

How to use annotations such as @notnull to verify and handle global exceptions
![[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)](/img/68/3721975cf33fcfacc28dc4d3d6a5ca.jpg)
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)

"Remake Apple product UI with Android" (2) -- silky Appstore card transition animation

Distributed task scheduling XXL job

Redis在Windows以及Linux系统下的安装

关于网页中的文本选择以及统计选中文本长度

Low level version of drawing interface (explain each step in detail)

How to thicken the brush in the graphical interface

Unity功能——Unity离线文档下载及使用
随机推荐
Find mapping relationship
Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!
Second kill system 3 - list of items and item details
Calibre LVL
Driver and application communication
MB10M-ASEMI整流桥MB10M
"Remake Apple product UI with Android" (3) - elegant statistical chart
Visual upper system design and development (Halcon WinForm) -3 Image control
分布式事务(Seata) 四大模式详解
Distributed task scheduling XXL job
Persisting in output requires continuous learning
Unity function - unity offline document download and use
App mobile terminal test [3] ADB command
How to use AAB to APK and APK to AAB of Google play apps on the shelves
Popular understanding of decision tree ID3
Detailed explanation of string function and string function with unlimited length
App移动端测试【4】apk的操纵
Unityshader - materialcapture material capture effect (Emerald axe)
CString的GetBuffer和ReleaseBuffer使用说明
找映射关系