Lise name of uploaded file

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
pierrepercee
Forum Members
Forum Members
Posts: 150
Joined: Thu Jan 10, 2013 8:02 am

Lise name of uploaded file

Post by pierrepercee »

Hello,

In Lise I have a "reference" extra field. When I use an "uploads file" type field, the name of the file stored in the file manager is simply that of the file sent. So if two files have the same name there are no uploads. I would like to concatenate the value of the "reference" field with that of the filename. Example :
file name: test001.pdf
Reference: 12-11-2022akdfj
Renamed file name: 12-11-2022akdfjtest001.pdf
Then I would like the storage directory to differ depending on the category of the object. I guess you can do it with a hook and a udt...
If anyone has an idea or a clue.... :)
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Lise name of uploaded file

Post by velden »

Yes, should be possible with Events and a UDT.
You will need to think it out well of course.
For example, every time an editor saves an (existing) item you will need to check if the file and/or category and/or reference have been changed to determine whether you have to do something with the filename and/or location.

For every scenario you should write a small process to follow. E.g. to prevent 'ghosted' files to stay on the server or to process files which shouldn't be processed.

The file naming and moving would involve pure PHP.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: Lise name of uploaded file

Post by Jo Morg »

pierrepercee wrote: Sat Nov 12, 2022 3:15 am When I use an "uploads file" type field, the name of the file stored in the file manager is simply that of the file sent. So if two files have the same name there are no uploads.
Although the File Upload type doesn't have yet that feature, you can use the directory name template to make sure that there won't be any clash.
Note the info box under the directory field on the field type editor:
Directory path that will be appended to $config['uploads_url'] . No slash at the end. {$item_id} and {$field_id} will be replaced.
So you can use {$item_id} and {$field_id} in a much simpler version of what you need.
Something like: MyLISEInstanceName/{$item_id} if only one upload field is used or MyLISEInstanceName/{$item_id}/{$field_id} as an example. LISE would also do the house cleaning in that case deleting files from deleted Items.
It's, in my view, a much simpler solution.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Lise name of uploaded file

Post by velden »

That sounds like a much easier way indeed.
pierrepercee
Forum Members
Forum Members
Posts: 150
Joined: Thu Jan 10, 2013 8:02 am

Re: Lise name of uploaded file

Post by pierrepercee »

Hello,
Thank you Velden. I hadn't seen that look. This makes things a little more complex. In PHP I suffer a lot, from time to time I still manage to achieve an acceptable result. The communication between smarty and the templates of different modules in CMSMS, there I no longer suffer, the ablation of the brain is effective...
Thanks Jo Morg for this simple solution. It is clearly more within my reach and I will adopt it.
I don't know if an option for adding a microtime() to the name of the uploaded file can be done without causing too many backward compatibility problems.
Same for the optional addition of a destination directory to each category.
In any case it would be two really powerful features. I say that but it's not me who develops. Fortunately, if not in 2050... ;D

Thanks again !
Post Reply

Return to “Modules/Add-Ons”