Hot File

Check File uploads with HTML5 and submit before Javascript

View: 553    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: References   Fields: Other

9 point/3 review File has been tested

The inspection of files before uploading always work necessary for any website or blog. Previously, in order to check files that are too large, or the file is not supported for uploading ... We often have to send that file to the server, then use programming languages like PHP to check if they have a valid No.

Introduction

The inspection of files before uploading always work necessary for any website or blog. Previously, in order to check files that are too large, or the file is not supported for uploading ... We often have to send that file to the server, then use programming languages like PHP to check if they have a valid No.

But in recent years, supporting HTML5 has many new features in the Web browser. One of them is the File API, this feature allows us to examine the entire name, capacity, and also verify that files have been supported or not on user machines without having to send back to the server. To verify what I said just now, we will try to practice turns checking the file before uploading as follows:

First, we need to implement upload html paragraph as follows:

1
2
<input id="i_file" type="file" value="" />
<input id="i_submit" type="button" value="Submit" />

Check the file size allowed (On the user's computer)

When we click upload, JavaScript will check whether the user's browser supports the File API or not. And then we will move to the next section is that the file size has reached or not.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
$('#i_submit').click( function() {
    //kiem tra trinh duyet co ho tro File API
    if (window.File && window.FileReader && window.FileList && window.Blob)
    {
        // lay dung luong va kieu file tu the input file
        var fsize = $('#i_file')[0].files[0].size;
 
        if(fsize>1048576) //thuc hien dieu gi do neu dung luong file vuot qua 1MB
        {
            alert(fsize +" bites\nToo big!");
        }else{
            alert(fsize +" bites\nYou are good to go!");
        }
    }else{
        alert("Please upgrade your browser, because your current browser lacks some new features we need!");
    }
});

Get the File name, type and size

The code below will return the name, size and file type is easy.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
$('#i_submit').click( function() {
   //kiem tra trinh duyet co ho tro File API
    if (window.File && window.FileReader && window.FileList && window.Blob)
    {
       // lay dung luong va kieu file tu the input file
        var fsize = $('#i_file')[0].files[0].size;
        var ftype = $('#i_file')[0].files[0].type;
        var fname = $('#i_file')[0].files[0].name;
 
        if(fsize>1048576)  //thuc hien dieu gi do neu dung luong file vuot qua 1MB
        {
            alert("Type :"+ ftype +" | "+ fsize +" bites\n(File: "+fname+") Too big!");
        }else{
            alert("Type :"+ ftype +" | "+ fsize +" bites\n(File :"+fname+") You are good to go!");
        }
    }else{
        alert("Please upgrade your browser, because your current browser lacks some new features we need!");
    }
});

Check files to be uploaded (on users)

The code below will help us limit the upload file types are allowed, as in this case only allows the image file.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$('#i_submit').click( function() {
   //kiem tra trinh duyet co ho tro File API
    if (window.File && window.FileReader && window.FileList && window.Blob)
    {
      // lay dung luong va kieu file tu the input file
        var fsize = $('#i_file')[0].files[0].size;
        var ftype = $('#i_file')[0].files[0].type;
        var fname = $('#i_file')[0].files[0].name;
 
       switch(ftype)
        {
            case 'image/png':
            case 'image/gif':
            case 'image/jpeg':
            case 'image/pjpeg':
                alert("Acceptable image file!");
                break;
            default:
                alert('Unsupported File!');
        }
 
    }else{
        alert("Please upgrade your browser, because your current browser lacks some new features we need!");
    }
});

These are just basic examples that you can do with File API, almost all browsers support this feature, but you must update to the latest version of your browser.

Check File uploads with HTML5 and submit before Javascript

Check File uploads with HTML5 and submit before Javascript Posted on 31-07-2015  The inspection of files before uploading always work necessary for any website or blog. Previously, in order to check files that are too large, or the file is not supported for uploading ... We often have to send that file to the server, then use programming languages like PHP to check if they have a valid No. 3/10 553

Comment:

To comment you must be logged in members.

Files with category

  • Instructions for installing and configuring Windows Live Mail on Windows 10 simple

    View: 2535    Download: 0   Comment: 0   Author: none  

    Instructions for installing and configuring Windows Live Mail on Windows 10 simple

    Category: References
    Fields: Other

    0/2 review
    Windows 10 pre-installed Mail application for managing personal email on the device. The latest version of this application but improved a lot and support other email accounts such as Gmail or Yahoo Mail but users almost no "salty" really with this...

  • Step by step instructions to create social networking buttons with CSS3

    View: 1840    Download: 0   Comment: 0   Author: none  

    Step by step instructions to create social networking buttons with CSS3

    Category: References
    Fields: Other

    0.75/6 review
    CSS3 help web designers have the ability to create buttons (buttons) very nice, today I will share with you two tips decoration for button in your web becomes radiant beauty that no need to use photoshop.

  • You should understand the CSS Box Shadow

    View: 1998    Download: 0   Comment: 0   Author: none  

    You should understand the CSS Box Shadow

    Category: References
    Fields: Other

    1.3181818181818/11 review
    Effects his shadow was introduced in the previous article, however, in this article, I will guide more specific about shadow attributes, you try it with anything. First we try to learn css following paragraph:

  • How to do button movement with beautiful CSS3

    View: 1671    Download: 0   Comment: 0   Author: none  

    How to do button movement with beautiful CSS3

    Category: References
    Fields: Other

    0/4 review
    Previously to create motion effects button, you must draw the button in photoshop, then switched to flash to make it possible to move. But now you need not spend too much time doing it, all because of the emergence of CSS3.

  • Create a dropdown menu with CSS3 effects with beautiful transtions

    View: 1962    Download: 0   Comment: 0   Author: none  

    Create a dropdown menu with CSS3 effects with beautiful transtions

    Category: References
    Fields: Other

    0.45/10 review
    More of the dropdown menu you want to introduce to you, this will have the effect menu transitions (converted background of menu background from pale to dark). This menu works well on browsers like FF, Chrome, Safary, but unfortunately did not work...

  • How to hack css for all browsers you should know

    View: 1590    Download: 0   Comment: 0   Author: none  

    How to hack css for all browsers you should know

    Category: References
    Fields: Other

    1.6875/8 review
    In the process of web design, which makes it the most headaches is how to design web pages that you can run on the browser. Especially when clients use the old as IE6 browser such. However, with this article, you will easily edit interface runs well...

  • Create Accordion with extremely beautiful CSS3

    View: 1982    Download: 0   Comment: 0   Author: none  

    Create Accordion with extremely beautiful CSS3

    Category: References
    Fields: Other

    0.9/5 review
    Accordion is a technique that helps you shortened the content that you want displayed on the website. It is often used for the display of submenus. In addition you can also use it for content, images. Before applying this procedure, you have to use...

  • Create the effect Hovercho images with Webkit and CSS3 is great

    View: 1690    Download: 0   Comment: 0   Author: none  

    Create the effect Hovercho images with Webkit and CSS3 is great

    Category: References
    Fields: Other

    1.125/4 review
    WebKit is one open source application framework provides the necessary components built one for your web browser. Along with CSS3, cả have contributed to very nice effect những previously only using JavaScript or JQuery thực beige.​

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd