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

Code Attachment Opens in Webpage

This discussion is related to the fileupload addon.
stevejwinstevejwin New
edited January 2014 in Vanilla 2.0 - 2.8

I have a forum in which we deal with a number of industry-specific platforms that use a lot of custom code files / extensions. They upload fine after adding them to config, but when attempting to download (you simply click on them) they open in a new webpage, displaying the code. I would just like for the attachment to be downloaded.

I searched, couldn't find a resolve for this. Has anyone else encountered this issue or can provide a solution? Many thanks!!

Tagged:

Comments

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    If you zip the files they will download. Certain file types like tiff will download. And text files. If you want to avoid the files being opened in anew window, just zip them.

    UnderDogstevejwin
  • peregrineperegrine MVP
    edited January 2014

    It will work only for new attachments created.

    here's a mod I tried that automatically zips txt files. which forces a zip download of the text.

    worked for me.

    it may work for you and someone may have improvements (for error checking zip and removing non-zipped version.)

    it's more of a concept thing.
    it does however produce a zip and a text file in your file uploads folder.

    in FileUpload plugin

    class.fileupload.plugin.php

    from

        // Move to permanent location
                $MoveSuccess = @move_uploaded_file($FileTemp, $SavePath);
                if (!$MoveSuccess)
                   throw new FileUploadPluginUploadErrorException("Internal error, could not move the file.", 9, $FileName);            
             }
    
    
    
    to
    
    
       $MoveSuccess = @move_uploaded_file($FileTemp, $SavePath);
    
                    // Move to permanent location
                 $ZipOnExtension = array("txt","sql","js","doc");
            if (InArrayI($Extension, $ZipOnExtension)) {
                        $data = implode("", file($SavePath));
                        $gzdata = gzencode($data, 9);
                        $fp = fopen("{$SavePath}.gz", "w");
                        fwrite($fp, $gzdata);
                         fclose($fp);
                        $Extension = ".gz";
                        $SaveFilename = $SaveFilename .  $Extension;
                        }
    
                if (!$MoveSuccess)
                   throw new FileUploadPluginUploadErrorException("Internal error, could not move the file.", 9, $FileName);            
             }
    

    however you could zip all txt files in your file uploads folder and change the extension in the media table to make old files work the same way.

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

    vrijvlinderUnderDogstevejwin
  • Just wanted to say thank you for all of the replies....much appreciated!

    vrijvlinder
  • hi! a lot of my users dont have winrar and unable to open the gz files...
    i tryed to change it to "zip" axtention but i couldnt....
    can somebody help me?

  • whu606whu606 I'm not a SuperHero; I just like wearing tights... MVP
    edited July 2014

    7-Zip, free and open source, should be able to open gz files:

    http://www.7-zip.org/

    hgtonightperegrine
  • yes sure...but for unknown reason the file is corrupted and i also think that asking all my users to install 7-zip is the same as asking them to zip their files :/

  • You can also simply deny all uploads except zip, and images. therefore they have no choice.

    grep is your friend.

Sign In or Register to comment.