I needed a way to access the filename of a file being uploaded or attached using the input file from a form. So, I created a nice little function to achieve this. Hopefully it comes in handy for someone.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<script> function getNameFromPath(strFilepath) { var objRE = new RegExp(/([^\/\\]+)$/); var strName = objRE.exec(strFilepath); if (strName == null) { return null; } else { return strName[0]; } } </script> |
Hi Richard
This looks like the function I require but maybe you can confirm…
I’ve produced a website for our local camera club and a few of us are uploading our pictures but the ftp process is a bit tricky for some less computerate users.
So I thought I’d use the html file upload on a basic form for them.
Unfortunately when they select a file it only shows the first part of the path and they’re not sure it’s the correct picture. I’d like to show just the filename, (and extension), below the select field so they can be sure about what they are uploading.
I know I can’t check filesizes for them with javascript but could I check that the name fits our layout? Basically I’m telling everyone to call their pictures p1.jpg, p2.jpg etc so they drop into the gallery in the right place.
Many Thanks
ROD
Thank you. Given enough time I could have come up with something like this, but i don’t need to because you did 🙂
Thank you Richard.
This came in handy for me!
Thanks Its Very useful code!
Thanks for this, makes my day a little more pleasant 🙂
Good work. Works very well!
Thanks a lot good work… 🙂
Thanks so much. It’s useful for me!