


This time I will bring you the steps required to determine the type and size of uploaded pictures , and what are the precautions for judging the type and size of uploaded pictures. The following is a practical case, let's take a look together. take a look. z
Here we use jQuery to determine the type and size of the uploaded image:
nbsp;html> <meta>
图片格式为:
图片大小为:
<script></script> <script> $(function(){ var p_1 = $('#p_1'), p_2 = $('#p_2'); $('body').on('change','#file',function(){ var path = $(this).val(), extStart = path.lastIndexOf('.'), ext = path.substring(extStart,path.length).toUpperCase(); //判断图片格式 if(ext !== '.PNG' && ext !== '.JPG' && ext !== '.JPEG' && ext !== '.GIF'){ alert('请上传正确格式的图片'); resetFile(); return false; }else{ p_1.html('图片格式为:' + ext); } //获取图片大小,注意使用this,而不是$(this) var size = this.files[0].size / 1024; if(size > 10240){ alert('图片大小不能超过10M'); resetFile(); return false; }else{ p_2.html('图片大小为:' + size.toFixed(2) + 'KB'); } }) //还原 function resetFile(){ //清空file表单的值,不能直接使用$('#file').val('')这种写法 $('form').html('<input type="file" id="file" />'); p_1.html('图片格式为:'); p_2.html('图片大小为:'); } }) </script>lastIndexOf()
The method retrieves the specified number from back to front String , if the specified character appears, return the position of the character, if not, return -1, the position starts counting from 0
toUpperCase()
Method conversion into uppercase letters
substring()
method intercepts the string, the first parameter is the starting position, the second parameter is the ending position (if omitted, the character will be intercepted by default end of the string), unlike the slice()
and substr()
methods, substring()
does not accept negative parameters
The slice()
method is the same as the substring()
method, the difference is that it accepts negative parameters (if the parameter is a negative number, the position is calculated from the end of the string)
substr()
method intercepts a string. The first parameter is the starting position, and the second parameter is the intercepted length (different from slice and substring). It is no longer recommended to use
Believe it After reading the case in this article, you have mastered the method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Detailed explanation of the steps to build the Koa project
angular6.0 implements component lazy loading function (with code)
The above is the detailed content of What steps are needed to determine the type and size of uploaded images?. For more information, please follow other related articles on the PHP Chinese website!
![如何在VirtualBox中增加磁盘大小[指南]](https://img.php.cn/upload/article/000/887/227/171064142025068.jpg)
我们经常遇到预定义磁盘大小没有空间容纳更多数据的情况?如果您在稍后阶段需要更多的虚拟机硬盘空间,则必须扩展虚拟硬盘和分区。在这篇文章中,我们将看到如何在VirtualBox中增加磁盘大小。增加VirtualBox中的磁盘大小重要的是要注意,您可能希望在执行这些操作之前备份您的虚拟硬盘文件,因为总是有可能出错。有备份总是一个好的做法。然而,该过程通常运行良好,请确保在继续之前关闭您的机器。有两种方法可以增加VirtualBox中的磁盘大小。使用图形用户界面扩展VirtualBox的磁盘大小使用CL

设置无线网络很常见,但选择或更改网络类型可能会令人困惑,尤其是在您不知道后果的情况下。如果您正在寻找有关如何在Windows11中将网络类型从公共更改为私有或反之亦然的建议,请继续阅读以获取一些有用的信息。Windows11中有哪些不同的网络配置文件?Windows11附带了许多网络配置文件,这些配置文件本质上是可用于配置各种网络连接的设置集。如果您在家中或办公室有多个连接,这将非常有用,因此您不必每次连接到新网络时都进行所有设置。专用和公用网络配置文件是Windows11中的两种常见类型,但通

Part1聊聊Python序列类型的本质在本博客中,我们来聊聊探讨Python的各种“序列”类,内置的三大常用数据结构——列表类(list)、元组类(tuple)和字符串类(str)的本质。不知道你发现没有,这些类都有一个很明显的共性,都可以用来保存多个数据元素,最主要的功能是:每个类都支持下标(索引)访问该序列的元素,比如使用语法Seq[i]。其实上面每个类都是使用数组这种简单的数据结构表示。但是熟悉Python的读者可能知道这3种数据结构又有一些不同:比如元组和字符串是不能修改的,列表可以

随着短视频平台的盛行,视频矩阵账号营销已成为一种新兴营销方式。通过在不同平台上创建和管理多个账号,企业和个人能够实现品牌推广、粉丝增长和产品销售等目标。本文将为您探讨如何有效运用视频矩阵账号,并介绍不同类型的视频矩阵账号。一、视频矩阵账号怎么做?要想做好视频矩阵账号,需要遵循以下几个步骤:首先要明确你的视频矩阵账号的目标是什么,是为了品牌传播、粉丝增长还是产品销售。明确目标有助于制定相应的策略。2.选择平台:根据你的目标受众,选择合适的短视频平台。目前主流的短视频平台有抖音、快手、火山小视频等。

Go函数可以返回多个不同类型的值,返回值类型在函数签名中指定,并通过return语句返回。例如,函数可以返回一个整数和一个字符串:funcgetDetails()(int,string)。实战中,一个计算圆面积的函数可以返回面积和一个可选错误:funccircleArea(radiusfloat64)(float64,error)。注意事项:如果函数签名未指定类型,则返回空值;建议使用显式类型声明的return语句以提高可读性。

使用动态语言一时爽,代码重构火葬场。相信你一定听过这句话,和单元测试一样,虽然写代码的时候花费你少量的时间,但是从长远来看,这是非常值得的。本文分享如何更好的理解和使用Python的类型提示。1、类型提示仅在语法层面有效类型提示(自PEP3107开始引入)用于向变量、参数、函数参数以及它们的返回值、类属性和方法添加类型。Python的变量类型是动态的,可以在运行时修改,为代码添加类型提示,仅在语法层面支持,对代码的运行没有任何影响,Python解释器在运行代码的时候会忽略类型提示。因此类型提

php写图片不显示不出来的解决办法:1、找到并打开php.ini文件;2、找到“extension=php_gd2.dll”,并将前面的分号去掉;3、重新启动服务器;4、在绘图前清一下缓存即可。

随着互联网的快速发展,自媒体已经成为了信息传播的重要渠道。自媒体平台为个人和企业提供了一个展示自己、传播信息的舞台。目前,市场上主要的自媒体平台有微信公众号、今日头条、一点资讯、企鹅媒体平台等。这些平台各有特色,为广大自媒体从业者提供了丰富的创作空间。接下来,我们将对这些平台进行详细介绍,并探讨自媒体平台的类型。一、主要的自媒体平台有哪些?微信公众号是腾讯推出的自媒体平台,为个人和企业用户提供信息发布和传播服务。它分为服务号和订阅号两种类型,服务号主要为企业提供服务,而订阅号则侧重于资讯传播。由


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools
