1074

modifications to upload_file in Trongate.php

Comments for “modifications to upload_file in Trongate.php”
 

Posted by mjim on Friday 21st January 2022 at 11:30 GMT

I added an upload file method to my project with files stored in the module.

I had to make changes to the upload_file method in Trongate.php because it only stores in the public folder, not the module.

I'm concerned that it will be overwritten in future updates.

What do you suggest to prevent this?

Based on the upload_picture method, here are the changes I made...

Here are my module settings for uploading a file, notice upload_to_module = true.
function _init_file_settings() {
    $file_settings['max_file_size'] = 10000;
    $file_settings['destination'] = 'certificates_files';
    $file_settings['target_column_name'] = 'file';
    $file_settings['upload_to_module'] = true;
    return $file_settings;
}


I pass this value to the upload_file method.
$config['upload_to_module'] = (!isset($file_settings['upload_to_module']) ? false : $file_settings['upload_to_module']);
$this->upload_file($config);


In the upload_file method in Trongate.php, I added a check for the upload_to_module value.
if (!isset($upload_to_module)) {
    $upload_to_module = false;
}


Further in the upload_file method in Trongate.php, I set the $target_destination to the module path if upload_to_module is true.
if ($upload_to_module == true) {
    $target_module = (isset($targetModule) ? $targetModule : segment(1));
    $target_destination = '../modules/'.$target_module.'/assets/'.$destination;
} else {
    $target_destination = '../public/'.$destination;
}
Level One Member

mjim

User Level: Level One Member

Date Joined: 6/01/2022

Posted by Myhiideas on Friday 21st January 2022 at 12:30 GMT

Hello,
Any code that you change in the engine folder when updated will overwrite you code.
I would make a file that has the changes that you make documenting the process of the changes.
That way you will have them with the app.
It sounds like the trongate.php file is the only engine folder file you change. Maybe a view file?
If a change happens then just compare your changes with the updated trongate.php file.
Should not happen very often. And you do not have to update if you do not want to.
Everything should still work.
Dan

Myhiideas

User Level: Guest

Date Joined: 1/11/2021

Posted by mjim on Friday 21st January 2022 at 13:50 GMT

Thanks Dan. Yes, Trongate.php is the only core file I changed so I will make a backup copy of my changes.
Level One Member

mjim

User Level: Level One Member

Date Joined: 6/01/2022

×