HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Retaining original filename after upload

I have recently moved our forum from naturnettet.com (ver. 2.1.8) to naturnettet.net (ver. 2.6.4).

I used to:
1) retain the original filenames after upload, and
2) save all uploaded files (jpg photos) in a separate folder for each member (.../uploads/photos/#memberID)

As a default, filenames are changed and every image uploaded seems to be placed in a new folder.

Where can I define/change these two conditions so that we can continue as before?

I believe that I made changes in core files (!) in the previous version but due to lack of programming skills, I am unable to find where and what to change.

In the library/core/class.upload.php it says: "237 - If there is a plugin that wants to store uploads at a different location or in a different way then they register themselves by subscribing to the Gdn_Upload_GetUrls_Handler event." but I haven't been able to find such plugin.

Can anyone explain how this can be done?

Comments

  • Both requests can be made possible but are not trivial and there normally is no need for that. Why should anybody care how files have been saved? What is the purpose of that request?

    If you just want to see those files, maybe showing a list of them somewhere:

    SELECT
      m.Name AS 'File Name',
      m.Path AS 'File Path',
      u.Name AS 'User Name',
      m.DateInserted AS 'Date Inserted'
    FROM
      GDN_Media m LEFT JOIN
      GDN_User u ON m.InsertUserID = u.UserID
    ORDER BY
      u.Name,
      m.DateInserted
    
  • We are photographers and use the forum to present photos and descriptions of what we see in nature - butterflies, birds etc.

    When I upload photos in different threads (discussions) all of them will be saved in the same folder.

    This we have done since 2009 (Vanilla 1 forum) and from 2015 (Vanilla 2) - but still, all my photos are saved in the same folder. This means that when visiting our website (naturnettet.dk) and clicking "Forumgalleri" and further clicking my name all my photos will be shown - direct link: http://naturnettet.com/2/uploads/forumbilleder/1/forumgalleri4.php - and likewise for all other members.

    By keeping the original file name, the species and date etc. is directly shown and the EXIF data will tell the details of the camera settings etc.

  • KristianBKristianB
    edited November 2018

    @R_J
    When I had the identical problem in 2015 it was solved by changing the ImageUpload plugin to the following:

    <?php if (!defined('APPLICATION')) exit();

    $PluginInfo['ImageUpload'] = array(
    'Name' => 'ImageUpload',
    'Description' => 'lightweight and simple image uploader',
    'Version' => '1.1.1',
    'RequiredApplications' => array('Vanilla' => '2.0.18.4'),
    'RequiredTheme' => FALSE,
    'RequiredPlugins' => FALSE,
    'MobileFriendly' => TRUE,
    // 'HasLocale' => TRUE,
    'RegisterPermissions' => FALSE,
    'Author' => "chuck911",
    'AuthorEmail' => 'contact@with.cat',
    'AuthorUrl' => 'http://vanillaforums.cn/profile/chuck911'
    );

    class ImageUploadPlugin extends Gdn_Plugin {

    public function DiscussionController_BeforeBodyField_Handler($Sender)
    {
        echo $Sender->FetchView($this->GetView('upload_button.php'));
    }
    
    public function PostController_BeforeBodyInput_Handler($Sender)
    {
        echo $Sender->FetchView($this->GetView('upload_button.php'));
    }
    
    public function Base_Render_Before($Sender) {
        if(!in_array(get_class($Sender), array('PostController','DiscussionController')))
            return;
        $Sender->AddDefinition('ImageUpload_Url',Url('/post/imageupload'));
        $Sender->AddDefinition('ImageUpload_Multi',C('Plugins.UploadImage.Multi',TRUE));
        $Sender->AddDefinition('ImageUpload_InputFormatter',C('Garden.InputFormatter', 'Html'));
        $Sender->AddDefinition('ImageUpload_MaxFileSize', C('Plugins.UploadImage.MaxFileSize', '2mb'));
        $Sender->AddCssFile('imageupload.css', 'plugins/ImageUpload/css');
        $Sender->AddJsFile('plupload.full.js', 'plugins/ImageUpload');
        $Sender->AddJsFile('imageupload.js', 'plugins/ImageUpload');
    }
    
    public function PostController_Imageupload_create()
    {
        try {
            $UploadImage = new Gdn_UploadImage();
            $TmpImage = $UploadImage->ValidateUpload('image_file');
            $UserID = Gdn::Session()->UserID;
    
            // Generate the target image name. 
            // $TargetImage = $UploadImage->GenerateTargetName(PATH_UPLOADS.'/imageupload', '', TRUE);
                                $TargetFolder = PATH_UPLOADS.'/forumbilleder';
                                $Name =$UploadImage->GetUploadedFileName();
                                $Subdir = $UserID . '/';
                                $TargetImage = "$TargetFolder/{$Subdir}$Name";
    
            $Props = $UploadImage->SaveImageAs($TmpImage,$TargetImage,C('Plugins.UploadImage.MaxHeight',''),C('Plugins.UploadImage.MaxWidth',1024));
            echo json_encode(array('url'=>$Props['Url'],'name'=>$UploadImage->GetUploadedFileName()));
        } catch (Exception $e) {
            header('HTTP/1.0 400', TRUE, 400);
            echo $e;
        }
    }
    

    }

    Since then (ver. 2.6.4) the function UploadImage can be found in .../library/core/... not just as a plugin.

    The ImageUpload plugin can still be chosen in the Dashboard/settings but even if I can see in config.php that the plugin is enabled:

    $Configuration['EnabledPlugins']['ImageUpload'] = true;

    it doesn't work. Even if Advanced Editing is disabled and the upload button becomes active a click there just opens the proper folder on my PC, I can choose the picture that I want to put into my comment but no picture is uploaded.

    Is the ImageUpload plugin incompatible with Vanilla 2.6.4 or is something missing somewhere in e.g. config.php?

    I hope that there is an easy solution to the problem - the plugin worked perfectly in Vanilla 2.1.8!

  • @R_J: Also for Image-SEO reasons keeping files names can be crucial.

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • @phreak said:
    @R_J: Also for Image-SEO reasons keeping files names can be crucial.

    Oh yes: DSC001.jpg :lol:

    But for a nature forum it makes perfectly sense having photos named "nice_butterfly", I certainly agree.

  • Like this:

    Gonepteryx rhamni 20170825-21742-900.jpg

    species - date - picture# - size (width px)

Sign In or Register to comment.