solved Download file name

Melih
Melih
@melih
5 years ago
198 posts
Hello everyone,

Is there a way to change the name of the image file when using module/download/something/item_id
It uses the title of the image, but i want to use id number. I noticed that if the title is empty system uses the original file name. How can i make it to use the item_id as file name in my custom module? I am guessing that probably make with a listener for download event but i don't know how :(

Thanks in advance
updated by @melih: 06/02/19 12:34:57PM
michael
@michael
5 years ago
7,714 posts
The "Magic View" that handles the /download/ url is directed to a function: view_jrCore_download_file().

Inside that function there IS an event firing that you can use the "Events and Listeners" system to listen for in your module, the event is 'download_file'

So if your module listens for that event, then when you return $_data if you have set:
$_data['download_file_name'] = "whatever_you_want.???"
That will set your file name.

You can see an example of a module using a listener for that event in the jrGallery module.

in the _init() function it does:
    jrCore_register_event_listener('jrCore', 'download_file', 'jrGallery_download_file_listener');
Then in the include.php file is that function jrGallery_download_file_listener() which looks like this:


/**
 * Watch for original image downloads
 * @param $_data array incoming data array
 * @param $_user array current user info
 * @param $_conf array Global config
 * @param $_args array additional info about the module
 * @param $event string Event Trigger name
 * @return array
 */
function jrGallery_download_file_listener($_data, $_user, $_conf, $_args, $event)
{ if (isset($_args['module']) && $_args['module'] == 'jrGallery') { if (!isset($_conf['jrGallery_download']) || $_conf['jrGallery_download'] != 'on') { header('HTTP/1.0 403 Forbidden'); header('Connection: close'); jrCore_notice('Error', 'you do not have permission to download this file'); exit; } } return $_data; }

for you, you'd adjust the internals to get the name right.
Melih
Melih
@melih
5 years ago
198 posts
Thank you Michael! I will try that

Tags