当前位置:网站首页>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
边栏推荐
- Microservice - declarative interface call openfeign
- Popular understanding of decision tree ID3
- Driver and application communication
- Tensorflow realizes verification code recognition (II)
- win32创建窗口及按钮(轻量级)
- Break through 1million, sword finger 2million!
- [list to map] collectors Tomap syntax sharing (case practice)
- 关于网页中的文本选择以及统计选中文本长度
- 请求头不同国家和语言的表示
- Redis high availability and persistence
猜你喜欢
![App mobile terminal test [5] file writing and reading](/img/f1/4bff6e66b77d0f867bf7237019e982.png)
App mobile terminal test [5] file writing and reading

Visual host system design and development (Halcon WinForm)

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

Microservice API gateway

How to thicken the brush in the graphical interface

Microservice - fuse hystrix

Popular understanding of ovo and ovr

Reading notes of "micro service design" (Part 2)

Creation and destruction of function stack frames

半监督学习
随机推荐
Wechat payment -jsapi: code implementation (payment asynchronous callback, Chinese parameter solution)
深度学习之三维重建
CString的GetBuffer和ReleaseBuffer使用说明
Visual host system design and development (Halcon WinForm)
秒殺系統3-商品列錶和商品詳情
Use percent sign in CString
软件安装信息、系统服务在注册表中的位置
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
[combinatorial mathematics] binomial theorem and combinatorial identity (binomial theorem | three combinatorial identities | recursive formula 1 | recursive formula 2 | recursive formula 3 Pascal / Ya
[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解
请做好3年内随时失业的准备?
pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
VC下Unicode和ANSI互转,CStringW和std::string互转
Driver and application communication
秒杀系统1-登录功能
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
pycharm错Error updating package list: connect timed out
坚持输出需要不断学习
Download and install common programs using AUR
Microservices Seata distributed transactions