blueimp / jQuery-File-Upload

File Upload widget with multiple file selection, drag&drop support, progress bar, validation and preview images, audio and video for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.
https://blueimp.github.io/jQuery-File-Upload/
MIT License
30.96k stars 7.96k forks source link

How to limit the size of the name shown ? #405

Closed cutmaster closed 12 years ago

cutmaster commented 13 years ago

If someone upload a file named : blabla_blibli_bloblo_blublu_aaaaaaaa_bbbbbbbbb_ccccccccc_dddddddddddd_eeeeeeeeee.jpg the div goes outside its container and sometimes it is not possible to see the download button nor the progress bar Is there a way to auto-reduce the {name} tag ? (I've tried on the upload.php program but it seems to not work for the two divs before having finished the upload).

LazyCoder2011 commented 13 years ago

I had the same problem, so to handle it i wrote a small function in javascript to crop the length of the filename.

function truncate(objFilename) {
/*IE returns the full file path, where ff does not, so check for slashes */
if (objFilename.indexOf("\\") != -1) {
var path_arr = objFilename.split("\\");
objFilename = path_arr[path_arr.length - 1];
}
var arr = objFilename.split('.');

if (arr[0].length > 30) { objFilename = arr[0].slice(0, 29) + "." + arr[1]; } return objFilename;
}

You need to wrap the function around where the filename is shown inside the function associated with buildUploadRow:

return $('<\/td>' + truncate(files[index].name)


It will only shorten the filenames visually, thus reducing the horrid breaking of the container. Images/Files that are sent to the server will retain their long names. Hope this helps ;-)

TF4 commented 12 years ago

I tried and tried, but I don't even know where to put the code :(

blueimp commented 12 years ago

Instead of using JS, I would advise you to use CSS to fix this issue, e.g.:

.files .name {
    max-width: 200px;
    word-wrap: break-word;
}
TF4 commented 12 years ago

Perfekt, thx! :D That should be implemented^^