<label id="akrgw"></label>
<bdo id="akrgw"></bdo>
<span id="akrgw"></span>
    1. <span id="akrgw"></span>

        \n\n  \n<\/form>\n圖片格式為:<\/p>\n圖片大小為:<\/p>\n
        	
        
        
        
        
        
        
        

        国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

        Home Web Front-end JS Tutorial How to get the uploaded image type and size

        How to get the uploaded image type and size

        Jun 08, 2018 pm 02:28 PM
        jquery upload image judgment size type

        This time I will show you how to get the type and size of the uploaded image, and what are the precautions for getting the type and size of the uploaded image. The following is a practical case, let's take a look.

        JQuery is used here to determine the type and size of the uploaded image:

        <!DOCTYPE html>
        <html>
        <head>
        <meta charset="utf-8">
        </head>
        <body>
        <form action="" method="">
          <input type="file" id="file" />
        </form>
        <p id="p_1">圖片格式為:</p>
        <p id="p_2">圖片大小為:</p>
        <script src="js/jquery-1.8.3.min.js"></script>
        <script>
        $(function(){
          var p_1 = $(&#39;#p_1&#39;),
            p_2 = $(&#39;#p_2&#39;);
          $(&#39;body&#39;).on(&#39;change&#39;,&#39;#file&#39;,function(){
            var path = $(this).val(),
            extStart = path.lastIndexOf(&#39;.&#39;),
            ext = path.substring(extStart,path.length).toUpperCase();
            //判斷圖片格式
            if(ext !== &#39;.PNG&#39; && ext !== &#39;.JPG&#39; && ext !== &#39;.JPEG&#39; && ext !== &#39;.GIF&#39;){
              alert(&#39;請(qǐng)上傳正確格式的圖片&#39;);
              resetFile();
              return false;
            }else{
              p_1.html(&#39;圖片格式為:&#39; + ext);
            }
            //獲取圖片大小,注意使用this,而不是$(this)
            var size = this.files[0].size / 1024;
            if(size > 10240){
              alert(&#39;圖片大小不能超過(guò)10M&#39;);
              resetFile();
              return false;
            }else{
              p_2.html(&#39;圖片大小為:&#39; + size.toFixed(2) + &#39;KB&#39;);
            }
          })
          //還原
          function resetFile(){
            //清空f(shuō)ile表單的值,不能直接使用$(&#39;#file&#39;).val(&#39;&#39;)這種寫(xiě)法
            $(&#39;form&#39;).html(&#39;<input type="file" id="file" />&#39;);
            p_1.html(&#39;圖片格式為:&#39;);
            p_2.html(&#39;圖片大小為:&#39;);
          }
        })
        </script>
        </body>
        </html>

        lastIndexOf()The method retrieves the specified string from back to front. If the specified character appears, Then return the position of the character, if not, return -1, the position starts counting from 0

        toUpperCase() method converts to uppercase letters

        substring () method intercepts a string. The first parameter is the starting position, and the second parameter is the ending position (if omitted, the end of the string will be intercepted by default), which is the same as slice()# The difference between ## and substr() is that substring() does not accept negative parameters

        slice()The method is the same as 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 the string, The first parameter is the starting position, and the second parameter is the length of interception (different from slice and substring). It is no longer recommended to use

        I believe you have mastered the method after reading the case in this article. More exciting Please pay attention to other related articles on php Chinese website!

        Recommended reading

        How to use vue to request local json

        ##React props and state attribute practical case explanation


        The above is the detailed content of How to get the uploaded image type and size. For more information, please follow other related articles on the PHP Chinese website!

        Statement of this Website
        The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

        Hot AI Tools

        Undress AI Tool

        Undress AI Tool

        Undress images for free

        Undresser.AI Undress

        Undresser.AI Undress

        AI-powered app for creating realistic nude photos

        AI Clothes Remover

        AI Clothes Remover

        Online AI tool for removing clothes from photos.

        Clothoff.io

        Clothoff.io

        AI clothes remover

        Video Face Swap

        Video Face Swap

        Swap faces in any video effortlessly with our completely free AI face swap tool!

        Hot Tools

        Notepad++7.3.1

        Notepad++7.3.1

        Easy-to-use and free code editor

        SublimeText3 Chinese version

        SublimeText3 Chinese version

        Chinese version, very easy to use

        Zend Studio 13.0.1

        Zend Studio 13.0.1

        Powerful PHP integrated development environment

        Dreamweaver CS6

        Dreamweaver CS6

        Visual web development tools

        SublimeText3 Mac version

        SublimeText3 Mac version

        God-level code editing software (SublimeText3)

        Hot Topics

        PHP Tutorial
        1502
        276
        jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

        Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

        Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

        Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ??the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

        How to increase disk size in VirtualBox [Guide] How to increase disk size in VirtualBox [Guide] Mar 17, 2024 am 10:10 AM

        We often encounter situations where the predefined disk size has no room for more data? If you need more virtual machine hard disk space at a later stage, you must expand the virtual hard disk and partitions. In this post, we will see how to increase disk size in VirtualBox. Increasing the disk size in VirtualBox It is important to note that you may want to back up your virtual hard disk files before performing these operations, as there is always the possibility of something going wrong. It is always a good practice to have backups. However, the process usually works fine, just make sure to shut down your machine before continuing. There are two ways to increase disk size in VirtualBox. Expand VirtualBox disk size using GUI using CL

        How to determine whether a date is the previous day in Go language? How to determine whether a date is the previous day in Go language? Mar 24, 2024 am 10:09 AM

        Question: How to determine whether the date is the previous day in Go language? In daily development, we often encounter situations where we need to determine whether the date is the previous day. In the Go language, we can implement this function through time calculation. The following will be combined with specific code examples to demonstrate how to determine whether the date is the previous day in Go language. First, we need to import the time package in the Go language. The code is as follows: import(&quot;time&quot;) Then, we define a function IsYest

        Introduction to how to add new rows to a table using jQuery Introduction to how to add new rows to a table using jQuery Feb 29, 2024 am 08:12 AM

        jQuery is a popular JavaScript library widely used in web development. During web development, it is often necessary to dynamically add new rows to tables through JavaScript. This article will introduce how to use jQuery to add new rows to a table, and provide specific code examples. First, we need to introduce the jQuery library into the HTML page. The jQuery library can be introduced in the tag through the following code:

        How to create a video matrix account? What types of matrix accounts do it have? How to create a video matrix account? What types of matrix accounts do it have? Mar 21, 2024 pm 04:57 PM

        With the popularity of short video platforms, video matrix account marketing has become an emerging marketing method. By creating and managing multiple accounts on different platforms, businesses and individuals can achieve goals such as brand promotion, fan growth, and product sales. This article will discuss how to effectively use video matrix accounts and introduce different types of video matrix accounts. 1. How to create a video matrix account? To make a good video matrix account, you need to follow the following steps: First, you must clarify what the goal of your video matrix account is, whether it is for brand communication, fan growth or product sales. Having clear goals helps develop strategies accordingly. 2. Choose a platform: Choose an appropriate short video platform based on your target audience. The current mainstream short video platforms include Douyin, Kuaishou, Huoshan Video, etc.

        How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

        How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

        What are the main self-media platforms? What are the types of self-media platforms? What are the main self-media platforms? What are the types of self-media platforms? Mar 21, 2024 pm 06:36 PM

        With the rapid development of the Internet, self-media has become an important channel for information dissemination. We-media platforms provide a stage for individuals and companies to showcase themselves and spread information. Currently, the main self-media platforms on the market include WeChat official accounts, Toutiao, Yidian News, Penguin Media Platform, etc. Each of these platforms has its own characteristics and provides a wealth of creative space for the majority of self-media practitioners. Next, we will introduce these platforms in detail and explore the types of self-media platforms. 1. What are the main self-media platforms? WeChat official account is a self-media platform launched by Tencent to provide information release and dissemination services for individual and corporate users. It is divided into two types: service account and subscription account. Service account mainly provides services for enterprises, while subscription account focuses on information dissemination. Depend on

        See all articles