Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Downloading attachments generates 'junk' file names, rather than the original file's name

DoyceTDoyceT Model Questioner ✭✭✭
edited September 2014 in Vanilla 2.0 - 2.8

Using 2.1.1 stable, with current FileUpload version.

When I download files from my forum, the files are not saved under their original titles (mousing over the attachment in the forum does display the correct name, however, so the correct file name information is 'there' somewhere).

For instance, a file uploaded as TheNightSputnikFlew.docx gets saved as ea59a4f38e1198e5de7da5599c2216.docx.

I'd very much like the system to default to saving the file using the original file name. Obviously, we can copy/paste to rename the file correctly, but we'd dearly like to be able to dispense with that step; a big chunk of what we use the forum for relates to workshopping fiction and nonfiction, so there are a ton of file attachment uploads and downloads happening, and anything that simplifies that element of the week is a huge plus.

Tagged:

Comments

  • peregrineperegrine MVP
    edited September 2014

    one way:

    look at line 847 in and modify SavePath in class.fileupload.plugin.php and modify and make sure to change thumbnail as well.

    or trigger off saveas with another plugin.

    something similar (but different :)) with image uploads plugin.

    http://vanillaforums.org/discussion/comment/214133/#Comment_214133

    if you don't figure it out or no one provides better answer, you can pm me if its worth a donation from you for me to spend the time and energy to pursue and test.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • however the easiest solution is to tell everyone to zip up the file and upload it - then when you unzip it, it will extract to the original name. plus it will take less room on your server and upload and download times will be faster.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • DoyceTDoyceT Model Questioner ✭✭✭

    Nice!

    I went into the plugin around line 833-ish and changed this:

    // Build filename
             $SaveFilename = md5(microtime()).'.'.strtolower($Extension);
             $SaveFilename = '/FileUpload/'.substr($SaveFilename, 0, 2).'/'.substr($SaveFilename, 2);
    

    To this:

    // Build filename
             $SaveFilename = md5(microtime()).'.'.strtolower($FileName);
             $SaveFilename = '/FileUpload/'.substr($SaveFilename, 0, 2).'/'.substr($SaveFilename, 2);
    

    It's not much, but retains the 'random junk' to keep files from overwriting each other, while still putting the original filename in the saved file's... name.

  • DoyceTDoyceT Model Questioner ✭✭✭
    edited September 2014

    Update to this:

    The 'random junk' was working fine, but it does make the file names quite long, so I fiddled with the random name generation and got this:

    // Build filename
             $SaveFilename = substr(str_shuffle(MD5(microtime())), 0, 7).'.'.strtolower($FileName);
             $SaveFilename = '/FileUpload/'.substr($SaveFilename, 0, 2).'/'.substr($SaveFilename, 2);
    

    Which, once everything is said and done, prepends 5 random characters to the start of the original filename: generally, this (plus the fact that the subfolder under /FileUpload/ is also randomly generated) is more than enough to ensure there won't be any accidental file overwrites, and doesn't make the file name terribly long.

Sign In or Register to comment.