15

I am placed a button for upload image files.I want to customize that button, i want to add more than one image file ,what is the logic to achive.

<input type="file" />,this is rendering a choose button with a text saying `no files choosen` in the same line.

Is it possible to customize the text "no files choosen"below the choose button.Meanwile i wise to keep an camera image before the no files choosen text.

How to perform this to improve my site.

Thanks

4 Answers4

48

You can hide the input by placing it into a div which is height:0px and overwflow:hidden. THen you add a button or an other html element which you can style as you want. In the onclick event you get the input field using javascript or jQuery and click it:

<div style="height:0px;overflow:hidden">
   <input type="file" id="fileInput" name="fileInput" />
</div>
<button type="button" onclick="chooseFile();">choose file</button>

<script>
   function chooseFile() {
      $("#fileInput").click();
   }
</script>

Now the input is hidden, but you can style the button as you want, it will always open the file input on click.

If you don't want to use jQuery replace the script tag with this script tag:

<script>
   function chooseFile() {
      document.getElementById("fileInput").click();
   }
</script>
Sébastien Garmier
  • 1,263
  • 9
  • 16
7

Try this manipulated solution. (I tried it today for one of my project :) )

HTML

  <div class="choose_file">
        <span>Choose File</span>
        <input name="Select File" type="file" />
    </div>

CSS

.choose_file{
    position:relative;
    display:inline-block;    
    border-radius:8px;
    border:#ebebeb solid 1px;
    width:250px; 
    padding: 4px 6px 4px 8px;
    font: normal 14px Myriad Pro, Verdana, Geneva, sans-serif;
    color: #7f7f7f;
    margin-top: 2px;
    background:white
}
.choose_file input[type="file"]{
    -webkit-appearance:none; 
    position:absolute;
    top:0; left:0;
    opacity:0; 
}

DEMO

Sowmya
  • 26,684
  • 21
  • 96
  • 136
1

You can customize it using only CSS. Go through the link below.

HTML

<label class="btn-upload">
   <input type="file" name="fileupload">
   <button class="btn">Browse</button>
</label>

.btn-upload {
    position: relative;
    overflow: hidden;
    display: inline-block;
}
.btn-upload input[type=file] {
    position: absolute;
    opacity: 0;
    z-index: 0;
    max-width: 100%;
    height: 100%;
    display: block;
}
.btn-upload .btn{
    padding: 8px 20px;
    background: #337ab7;
    border: 1px solid #2e6da4;
    color: #fff;
    border: 0;
}
.btn-upload:hover .btn{
    padding: 8px 20px;
    background: #2e6da4;
    color: #fff;
    border: 0;
}

http://imdebasispanda.blogspot.in/2015/08/custom-upload-button-using-css.html

Debasis Panda
  • 433
  • 1
  • 6
  • 15
0
    <body>

    <style>
   .image{
  position:relative;
   display:inline-block;    
     width:3%; 
   padding: 0%;
    }
.image input[type="file"]{
-webkit-appearance:none; 
position:absolute;
    top:0; left:0;
    opacity:0; 
     }
   </style>

  <div class="image">
    <span><img src='admin/ico/fms.ico' class "image"></span>
    <input name="image" type="file" />
  </div>
</body>
J.Mbai
  • 1
  • Please add some text _how_ this answers the question. – Zeta Feb 12 '17 at 16:50
  • this code works better when you want to use an image as an upload button. just replace my image with yours and it will work – J.Mbai Feb 14 '17 at 17:10
  • Please [edit] additional information into your answer. Comments can be deleted, and their contents can get lost. – Zeta Feb 14 '17 at 20:32