Images Only Upload

4

How to only upload images ( .png and .jpeg )? Do not allow the choice of another file type.

I'm using as below:

 <input type="file" name="arquivos" class="btn btn-success" multiple/>

At the time of selecting the photos I do not want to allow the choice of other types of files.

    
asked by anonymous 30.05.2015 / 16:26

1 answer

6

Put this in the <input> tag

<input type="file" name="arquivos" class="btn btn-success"  accept="image/png, image/jpeg"  multiple /> 

Now the button will accept only image files with .jpeg and .png extension (nor will it show other options in the file selection area)

Add to <form> onsubmit="Checkfiles(this)" and put a id into your input .

using javascript code together:

function Checkfiles(){
    var fup = document.getElementById('filename');
    var fileName = fup.value;
    var ext = fileName.substring(fileName.lastIndexOf('.') + 1);

    if(ext =="jpeg" || ext=="png"){
        return true;
    }
    else{
        return false;
    }
}
    
30.05.2015 / 16:36