How to limit the characters in file name preview selected for upload?

Feroz

I am using twitter bootstrap framework. I am clicking upload button and then we select a file that need to be uploaded.Then the upload button is changed to change and name of selected file is displayed next to it.But if we are having a big file name i want to limit the file name characters to about 50.How to achieve this ?

<div class="span5">
        <div class="fileupload fileupload-new"
         data-provides="fileupload">
         <span class="btn btn-file" id="uploadRef"> <span class="fileupload-new">Upload
           Referral Script</span> <span class="fileupload-exists">Change</span>
          <form:input type="file" path="refuploadScript"
           onchange="return checkFileExists();" />
         </span> <span class="fileupload-preview"></span>


          <a href="#"
          class="close fileupload-exists" data-dismiss="fileupload"
          style="float: none">x</a>
        </div>
</div> 
boniezuvyz

For doing this, first hide the default file name display span. Then process the file name and display it separately.

So, to hide the default :

<span class="fileupload-preview" style="display: none;"></span>

on form input change , call the following script function

function truncatefile() // calling a function on change or select
{                           
   var fup = document.getElementById('patientupload'); //store file by ID
   var file = fup.files[0]; // store value of file
   var filePath = fup.value; 
   var name;                
   if(filePath=="")                 
   {                    
      document.getElementById('fname').innerHTML = '';                  
   }                
   else                 
   {                    
      name=filePath.replace(/^.*[\\\/]/, '');

      var ext = filePath.substring(filePath.lastIndexOf('.') + 1);//getting file extension

      var fileName = name.substring(0,name.length-4); // storing 0th position till extension begining

      var fileNameNew=""; 
      if(fileName.length > 30)  
      {
         var fileNameFst=fileName.substring(0,24); //firstpart of file
         var fileNameLst=fileName.substring(fileName.length-5,fileName.length); //last part of file
         fileNameNew=fileNameFst+ "...." + fileNameLst+"."+ext; //combine all parts         
      }         
      else
      {         
         fileNameNew=fileName+"."+ext; //if length less than 30 
      }                     
      document.getElementById('fname').innerHTML = fileNameNew;                 
   }

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Upload image with file name that not in english

분류에서Dev

How to limit string characters when rendered in MeteorJS

분류에서Dev

AppleScript to get name of single selected file in finder

분류에서Dev

How to display selected file name when using the Dropbox API JS Chooser

분류에서Dev

preview image after upload

분류에서Dev

How to shorten the amount of characters in the preview snipet of my wordpress blog

분류에서Dev

How to preview a VB6 .frm file?

분류에서Dev

Can I limit the file size for a attachinary/cloudinary upload

분류에서Dev

spring3 file upload and save - extra null characters at the end

분류에서Dev

How to upload file to HDFS in Ubuntu

분류에서Dev

how to upload a pdf file to ftp server using file upload controller?

분류에서Dev

How to remove limit on core dump file size

분류에서Dev

AIX: How to find sftp file limit?

분류에서Dev

How to set a file size limit for a directory?

분류에서Dev

How can I preview Windows files without file extension?

분류에서Dev

Can not delete files containing special characters in the file name

분류에서Dev

If statement confusion - how to display a div if file is selected

분류에서Dev

How to print selected elements from file?

분류에서Dev

How can I give a table column name as "limit" in Postgres

분류에서Dev

How can i replace particular characters in a file

분류에서Dev

Upload size limit in bytes (django)

분류에서Dev

How to insert selected content of a file into another file after a pattern?

분류에서Dev

Limit the amount of characters typed into a JTextField

분류에서Dev

Limit an input characters to just number

분류에서Dev

Does websites know the folder name when I upload a file from that folder?

분류에서Dev

How to edit selected file in a dropdown list in textarea and then save it?

분류에서Dev

Header in Print Preview is different from workbook name

분류에서Dev

How to upload file into specific folder with Google Drive API and Python?

분류에서Dev

How to make a MediaWiki User required to select license on file upload

Related 관련 기사

  1. 1

    Upload image with file name that not in english

  2. 2

    How to limit string characters when rendered in MeteorJS

  3. 3

    AppleScript to get name of single selected file in finder

  4. 4

    How to display selected file name when using the Dropbox API JS Chooser

  5. 5

    preview image after upload

  6. 6

    How to shorten the amount of characters in the preview snipet of my wordpress blog

  7. 7

    How to preview a VB6 .frm file?

  8. 8

    Can I limit the file size for a attachinary/cloudinary upload

  9. 9

    spring3 file upload and save - extra null characters at the end

  10. 10

    How to upload file to HDFS in Ubuntu

  11. 11

    how to upload a pdf file to ftp server using file upload controller?

  12. 12

    How to remove limit on core dump file size

  13. 13

    AIX: How to find sftp file limit?

  14. 14

    How to set a file size limit for a directory?

  15. 15

    How can I preview Windows files without file extension?

  16. 16

    Can not delete files containing special characters in the file name

  17. 17

    If statement confusion - how to display a div if file is selected

  18. 18

    How to print selected elements from file?

  19. 19

    How can I give a table column name as "limit" in Postgres

  20. 20

    How can i replace particular characters in a file

  21. 21

    Upload size limit in bytes (django)

  22. 22

    How to insert selected content of a file into another file after a pattern?

  23. 23

    Limit the amount of characters typed into a JTextField

  24. 24

    Limit an input characters to just number

  25. 25

    Does websites know the folder name when I upload a file from that folder?

  26. 26

    How to edit selected file in a dropdown list in textarea and then save it?

  27. 27

    Header in Print Preview is different from workbook name

  28. 28

    How to upload file into specific folder with Google Drive API and Python?

  29. 29

    How to make a MediaWiki User required to select license on file upload

뜨겁다태그

보관